Skip to content

Instantly share code, notes, and snippets.

View bbbradsmith's full-sized avatar
🦎

Brad Smith bbbradsmith

🦎
View GitHub Profile
@bbbradsmith
bbbradsmith / affine_texture_mapping_tri_vs_quad.py
Created December 30, 2022 04:45
Texture mapping diagrams for Wikipedia
# generates SVG diagram:
# https://commons.wikimedia.org/wiki/File:Affine_texture_mapping_tri_vs_quad.svg
import math
GRID = 8
FTW = 100 # top board width
FBW = 200 # bottom board width
FH = 156
COLBG = "#B4B3D2"
@bbbradsmith
bbbradsmith / baricentric_perspective.py
Last active December 29, 2022 21:31
baricentric_perspective rendering
# A recreation of:
# https://commons.wikimedia.org/wiki/File:Perspective_correct_texture_mapping.jpg
#
# To give a simple code demonstration of perspective correction,
# and simple barycentric triangle coordinates.
#
# Note that this is a "naive" implementation,
# and the resulting floating point errors will produce some rough edges on the checkerboard texture.
# It would be more efficient and more numerically stable to rasterize the triangle instead,
# but this demonstrates a simple way to generate coordinates without the additional complexity of rasterization.
@bbbradsmith
bbbradsmith / talosv_dump.py
Created November 17, 2022 02:40
Vigilance on Talos V DOS graphics and map extractor
# Sprite / Map dumper for Vigilance on Talos V (19960
# place in "dump" folder within Talos install directory and run
import os
import struct
import PIL.Image
DEFAULT_BG = 13 # magenta
def filename_flatten(f):
@bbbradsmith
bbbradsmith / sinaria_dump.py
Created November 17, 2022 01:45
Sinaria Lost in Space DOS graphics and map extractor
# Sprite / Map dumper for Sinaria: Lost in Space (1994)
# place in "dump" folder within Sinaria install directory and run
import os
import struct
import PIL.Image
#DEFAULT_BG = 27 # red
DEFAULT_BG = 140 # magenta
@bbbradsmith
bbbradsmith / nsfe_to_nsf2.py
Last active November 5, 2022 09:12
Utility to convert NSFe music files into the backward compatible NSF2 with metadata format.
#!/usr/bin/env python3
import sys
assert sys.version_info[0] >= 3, "Python 3 required."
#
# nsfe_to_nsf2.py
# Brad Smith, 2018-08-24
#
# This converts an NSFe file to a preliminary "NSF2 with metadata" format.
#
@bbbradsmith
bbbradsmith / icekiss_sprite_bin_dump.py
Last active September 20, 2022 07:53
Ice Kiss (DOS) graphics extractor
# Extracts sprites from the Korean DOS game Ice Kiss
# First run icekiss_sprite_file_extract.py to create the sprite bin files
# Also, take a screenshot of the gameplay with DOSBox to make a PNG with the correct palette
# Then run this to extract graphics from them
import PIL.Image
screenshot = PIL.Image.open("screenshot.png") # use for palette
def decode_file(filename):
@bbbradsmith
bbbradsmith / circlemap.py
Last active June 19, 2022 10:04
Example renderings of the chaotic Circle Map. - Details: https://www.patreon.com/posts/24826459
#!/usr/bin/env python3
#
# circlemap.py
# Brad Smith, 2019
# http://rainwarrior.ca
#
# Example renderings of the chaotic Circle Map.
# http://mathworld.wolfram.com/CircleMap.html
import sys
@bbbradsmith
bbbradsmith / stx_to_st.py
Created December 14, 2021 07:24
Pasti STX to ST conversion utility, for analyzing partial conversions from STX of damaged/copy-protected disks.
#!/usr/bin/env python3
#
# Pasti .STX Atari ST image to .ST image converter.
# Creates an ST file using the sectors found in an STX, and reports missing/error sectors.
#
# Usage:
# stx_to_st("a.stx")
# stx_to_st("in.stx","out.st",tracks,sides,sectors)
#
@bbbradsmith
bbbradsmith / iga_ninden_gaiou_text.py
Created November 1, 2021 04:55
Iga Ninden Gaiou text extraction (unfinished)
# Files:
# Iga Ninden Gaiou (Japan).chd CRC32 1243A2DE
#
# Use chdman to extractcd:
# ing.bin CRC32 07E9BA8D
romin = "ing.bin"
romout = "inge.bin"
rom = open(romin,"rb").read()
@bbbradsmith
bbbradsmith / stx_dump.py
Last active June 18, 2021 03:52
Pasti STX disk image python info dumper (Atari ST)
#!/usr/bin/env python3
#
# Pasti .STX Atari ST disk image info dumper
# Prints out a human-readable version of all data found in the file
#
# Usage:
# stx_dump("a.stx")
#
# Based on Pasti reverse engineering: