Skip to content

Instantly share code, notes, and snippets.

@kajott
kajott / EGATEST.BAS
Created September 1, 2018 18:26
test program to find out whether EGA 200-line mode palette manipulation might be feasible after all
10 SCREEN 0: REM This program makes only sense to be run on EGA cards, not VGA!
20 SCREEN 9: H% = 105: GOSUB 1000: LOCATE 9
30 PRINT "Notice the nice rainbow colors above? That's what you can get by reprogramming"
40 PRINT "the EGA palette. Unfortunately, this only works in 350-line mode."
50 PRINT "Press any key to see what it looks like in 200-line mode."
60 WHILE INKEY$ = "": WEND
70 SCREEN 8: H% = 60: GOSUB 1000: LOCATE 9
80 PRINT "Well, that's not nearly as nice as it was in 350-line mode. Turns out, the EGA"
90 PRINT "monitor emulates a CGA monitor in 200-line mode and thus restricts the palette"
100 PRINT "to the 16 CGA colors. Reprogramming the EGA palette can shuffle the CGA colors"
@kajott
kajott / aoc2018_10_adversarial.txt
Created December 18, 2018 10:31
adversarial input for Advent of Code 2018 Day 10
position=<-58825, 5905> velocity=< 8, -6>
position=< 50749, -19111> velocity=<-7, 4>
position=< 50995, -8236> velocity=<-3, -5>
position=< 44611, -17672> velocity=<-8, 1>
position=< 41069, -41189> velocity=<-8, 3>
position=< 9181, -56028> velocity=<-6, 2>
position=<-24979, 38514> velocity=<-2, 1>
position=< 19502, 58516> velocity=<-3, -9>
position=< 58524, 6506> velocity=<-9, -1>
position=<-47781, 14688> velocity=<-1, -3>
@kajott
kajott / mad.bas
Created July 5, 2019 16:21
The MAD Computer Program, ported to Sinclair ZX Spectrum
10 CLS : RESTORE 500
20 READ x,y,u,v
30 IF x=999 THEN GOTO 70
40 PLOT 128+x, 88+y : DRAW u-x, v-y
50 PLOT 129+x, 88+y : DRAW u-x, v-y
60 GOTO 20
70 PRINT AT 21,9; "WHAT, ME WORRY?"
80 IF INKEY$ = "" THEN GOTO 80
90 CLS : PRINT "\* 1985 E.C. PUBLICATIONS"
500 DATA -27,-11,-23,-6,-28,-13,-22,-6,-20,-5,-12,-5,-27,-14,-26,-13
@kajott
kajott / joymap.c
Created August 1, 2019 20:34
joystick quantization visualization
#if 0
gcc -std=c99 -Wall -Wextra -pedantic -g -O4 -march=native $0 -lm || exit 1
./a.out && feh joymap.ppm
exit $?
#endif
// visualization of analog joystick to 8-way digital direction quantization
// see https://github.com/sulix/omnispeak/pull/14
#include <stdbool.h>
@kajott
kajott / variable_randomness.cpp
Last active August 8, 2019 19:51
generate sequences of numbers with variable degree of randomness
#if 0
g++ -std=c++11 -Wall -Wextra -pedantic -Werror $0 || exit 1
exec ./a.out
#endif
// generate sequences of numbers 0..(1-n) with variable degree of randomness:
// r = 0.0 -> perfectly sorted
// r = 0.5 -> fully shuffled
// r = 1.0 -> perfectly reversed
@kajott
kajott / sortvis.py
Last active August 8, 2019 21:25
visualization of various in-place sorting algorithms
#!/usr/bin/env python3
"""
Visualization of various in-place sorting algorithms.
Can generate a HTML page and video files to browse and display the results.
Note: requires FFmpeg to display and export the visualizations.
The code snippets in the HTML report are syntax highlighted if Pygments
is installed.
@kajott
kajott / ktxview.c
Last active March 12, 2020 09:46
simple OpenGL-based KTX texture file viewer
#if 0 // self-compiling code
cc -std=c99 -Wall -Wextra -pedantic -Werror -g -O4 $0 -o ktxview `sdl2-config --cflags --libs` -lGL -lm || exit 1
exec ./ktxview $*
#endif
// simple OpenGL-based KTX texture file viewer
//
// features:
// - simple, based on SDL2 and OpenGL Compatibility Profile
// - self-compiling on GNU/Linux and similar platforms
@kajott
kajott / clock.asm
Created December 6, 2020 16:25
clock screensaver for DOS
; clock screensaver in 670 bytes (DOS, 186+)
;
; features:
; - VGA mode 13h
; - 24-hour clock in pixellated LED clock style
; - animated screen position
; - smooth alpha-blended transition between seconds
; - fade-in on startup, fade-out on exit
; - smoothly changing colors
;
@kajott
kajott / image_predict.c
Created May 4, 2018 07:14
channel separation, color decorrelation, and prediction filtering as preprocessing for lossless RGB image compression
#if 0 // self-compiling code
gcc -std=c99 -Wall -Wextra -pedantic -g -O3 -march=native $0 -o image_predict || exit 1
exec ./image_predict $*
#endif
// Example code for pre-filtering operations that transform RGB images into
// representations that are better suited for lossless compression
// (color channel separation and decorrelation, pixel prediction).
// Takes a .ppm file as an input and generates multiple files in the form
@kajott
kajott / bluenoise.c
Created June 26, 2019 10:49
Blue Noise texture generation using the void-and-cluster algorithm
#if 0 // self-compiling code
gcc -std=c99 -Wall -Wextra -pedantic -Werror -g -O4 -march=native $0 -lm || exit 1
exec time ./a.out
#endif
// Blue Noise texture generation using the void-and-cluster algorithm
// implemented by Martin Fiedler <keyj@emphy.de>
// using an algorithm description written by Alan Wolfe:
// https://blog.demofox.org/2019/06/25/generating-blue-noise-textures-with-void-and-cluster/