Skip to content

Instantly share code, notes, and snippets.

@jgamble
jgamble / hercbyte.asm
Created January 27, 2023 04:34
Like hercdot.asm, write pixels onto the screen with the Hercules graphics card, but a byte's worth at a time instead of pixel by pixel., which was a significant speed-up on 8086 computers.
;
; Hercbyt -- write out a byte's worth of dots in the correct position
; for the Hercules graphics board. This is a variation on hercdot,
; which writes out only a dot at a time.
;
; Invocation: hercbyt(the_byte, y, x)
; the_byte = {0..255}
; y = {0..347}
; x = {0..712}, a multiple of 8, to stay on a byte boundry.
;
@jgamble
jgamble / hercdot.asm
Created January 27, 2023 04:02
Very old code from 1985. Set a pixel on the screen using the Hercules graphics card (see https://en.wikipedia.org/wiki/Hercules_Graphics_Card).
;
; Hercdot -- write out a dot in the correct position for the Hercules
; graphics board. There are only two colors available: black or white.
;
; Invocation: hercdot(color, y, x)
; color = {0, 1}
; y = {0..347}
; x = {0..719}
;
; In order to use the hercules graphics board, you have to
@jgamble
jgamble / hercmode.asm
Created January 27, 2023 03:39
Very old code from 1987. Switch the Hercules Graphics Card (see https://en.wikipedia.org/wiki/Hercules_Graphics_Card) to graphics mode or text mode.
; HERCMODE -- Mode switch for Hercules Graphics board.
; Copied from the Hercules owner's manual, edition 2.1, pg 20.
;
; port address
index equ 03b4h
cntrl equ 03b8h
;
; control codes
scrn_on equ 8
grph equ 2
@jgamble
jgamble / PrimeOffsetArray.c
Created October 16, 2019 21:33
Simply a pair of arrays to create the highest (or lowest) prime that is n bits wide. Entered as C, but written in an array form that should be common across most languages. See comments below.
//
// Offsets for creating the highest prime that fits in n bits; the
// highest prime less than 2**n.
//
// n can range from 1 .. 128. If arrays are zero-based in the language
// you want to use, subtract 1 from n before indexing.
//
// I.e.,
// hp24 = (1 << 24) - hiprimeoffset[24];
//
@jgamble
jgamble / imp_triangle.ps
Created June 19, 2018 21:03
Impossible Triangle Illusion in Postscript, by Guy Shaw (circa 1990)
%!
% M. C. Escher style impossible triangle
% written by Guy Shaw
% Things that are easy to play with:
% Position on paper, overall size, and linewidth
/inch { 72 mul } bind def
2 inch dup translate
3 inch dup scale
@jgamble
jgamble / hexpaper.ps
Last active June 19, 2018 19:55
Hexpaper In Postscript, by Daniel C. Nygren (posted on USENET in 1994). Settings (hex size, page size, etc) are set in-place, I've never felt the need to write a wrapper for it.
%!PS-Adobe-1.0
% hexpaper.ps - Version 1.0 : Hexagon mapping paper in PostScript
%
% Copyright 1994 by Daniel C. Nygren
% Current e-mail: nygren@tecnet1.jcte.jcs.mil
%
% Permission to use and modify this software for any purpose other than
% commercial use or its incorporation into a commercial product is
% hereby granted without fee. Permission to copy and distribute this software
% only for non-commercial use is also granted without fee, provided that
@jgamble
jgamble / bitpattern.pl
Created April 17, 2018 01:37
Create a list of bits according to the cyclic pattern you provide. The list may then be used as-is, joined to form a string, or packed into an integer.
#
# @bits = bitpattern($pattern, $length, $offset);
#
# Create a list of bits in a cyclic pattern.
#
# $pattern is an array reference containing the on (ones) and
# off (zeros) sequence of the pattern.
#
# $length is the length of the bitpattern to return.
#
@jgamble
jgamble / hexdist.pl
Last active June 27, 2016 04:15
Find the distance between two points on a hexagonal grid. Problem defined by Pete Stewart in 2002, solved by Tom Ruschak and Tanya Gilham.
#
# For calculating the diagonal distance, it is important to
# know which columns are shifted up (see the diagram below in
# the hexagon_distance() function).
#
# For the purposes of this code snippet we have a simple
# function that defines the odd-numbered columns as 'up'.
#
sub upcolumn
{
@jgamble
jgamble / spiro.f
Last active October 23, 2018 22:44
Spirograph simulation -- rediscovered the code from an August 1983 printout. There are two routines, SPIRO and XPIRO
C
C Subroutine spiro simulates the designs of the toy spirograph.
C Where:
C R1 -- The radius of the stationary wheel.
C R2 -- The radius of the moving 'pen' wheel.
C P -- The pen's distance from the center of the 'pen' wheel.
C ANGLE -- The angle by which the drawn figure is rotated, in degrees.
C STEP -- The increment of rotation of the pen wheel around the
C stationary wheel, in degrees.
C X, Y -- Arrays to hold the X and Y coordinates of the design.
@jgamble
jgamble / list_from_file.pl
Created April 20, 2016 22:35
Perl function for quick read of a list file
=head3 list_from_file()
@list = &list_from_file($filename, $comment_patrn, $keep_empty);
$filename - The file to open.
$comment_patrn - (Optional) A pattern that represents end-of-line style comments.
$keep_empty - (Optional) Add or do not add empty (no non-blank characters) lines.
Take a file containing a list of items. For each line, strip off any
characters following and including the comment character(s). Strip off