Skip to content

Instantly share code, notes, and snippets.

@digarok
digarok / f256-sprite-cutter.py
Created April 7, 2024 21:58
Input a png and a textfile to cut out sprites to source code.
from PIL import Image
import sys
from math import sqrt
def uniquepalette(image):
hist = set()
for j in range(image.size[1]):
for i in range(image.size[0]):
hist.add(image.getpixel((i,j)))
return hist
import struct, sys
def unpack_bytes(len, bytes):
if len == 3:
bytes.extend(b'\x00')
return struct.unpack('<I', bytes)[0]
def read_pgz_file(file_path):
with open(file_path, 'rb') as file:
# Read the file type signature (first byte)
@digarok
digarok / az_lister.sh
Created April 4, 2022 14:09
List all the regions and availability zones under your current AWS profile.
for R in `aws ec2 describe-regions --query 'Regions[*].RegionName' --output text` ; do ; echo "Region: $R" ; echo "`aws ec2 describe-availability-zones --region $R --query \"AvailabilityZones[*].[ZoneName, ZoneId]\" --output text`" ; done
## gcleanup #####
# I used to have a one liner but it was janky so reverting to a full blown function by golly gosh gee.
# I like to show the branches if they don't specify one, but in oh_my_zsh they have some interactive thing
# you need to turn off like:
# $ git config --global pager.branch false
#
gcleanup_function() {
if [ -z $1 ] ; then echo "You must specify a branch to cleanup." ; git branch ; return -1; fi
git checkout master
@digarok
digarok / datagridder.py
Created July 14, 2021 16:02
Take a list of assembly DEFINE BYTE statements ( " DB $2C") and print them at various grid sizes to look for patterns/alignment.
import fileinput,re,time
# parameters
pattern_DEFINE_BYTE='^.+DB\s+\$([a-fA-F0-9][a-fA-F0-9])'
pause_seconds=0.5
grid_range = range(4,33) # range is not inclusive
join_str = "" # change to comma if you want CSV
def print_chunked(datalist, chunksize):
for i in range(0, len(datalist), chunksize):
* Disassembly of @deater object tweet https://twitter.com/deater78/status/1368790980237791232
* by @65816guy / digarok/ Dagen Brock
00/00E7: 20 D8 F3 JSR F3D8 ; HGR2 -- set hi-res, page2, full graphics
00/00EA: 8A TXA
00/00EB: 20 11 F4 JSR F411 ; HPOS2 - positions hi-res cursor without plotting
; (A) = Y-coordinate, (Y,X) = X-coordinate
00/00EE: A2 01 LDX #01
00/00F0: A0 F0 LDY #F0
00/00F2: 20 5D F6 JSR F65D ; XDRAW - Draws a shape inverting dots (eor/xor) on screen.
; (A) = rotation, (Y,X) = address of the shape table
@digarok
digarok / trust.bas
Created September 6, 2020 01:26
A nice HGR "floral" effect for Apple II computer in AppleSoft BASIC.
REM "Trust the voice inside of you" - Digarok 2020-09-04
REM Reference: "Three Ways of Looking At A Function""
REM by James Fuller
REM January 1983 (c) Creative Computing
100 DEF FN R(Q) = COS(9 * SIN(2*Q)) : HGR : POKE -16302,0: SZ=5:
700 FOR BB=SZ TO 0 STEP -1: SX=2*BB/SZ:SY=SX:HCOLOR=RND(1)*7+1
800 FOR G = 0 TO 360 STEP 1
810 T = G / 57.29576
820 X = FN R(T) * COS(T) : Y = FN R(T) * SIN(T)
@digarok
digarok / c2-to-animgif.py
Last active July 31, 2022 16:11
Convert PaintWorks Animation (Apple IIgs $C2 filetype) to Animated GIF
# Example: python c2-to-animgif.py anim.c2 outputname.gif
from PIL import Image,ImageDraw # `pip3 install pillow==7.0.0` if you don't have it
from sys import argv, stdout
import glob, tempfile, struct, os
def get_scanline_palette(scanline):
scb = shr_buffer[0x7D00+scanline] # SCBs start at $E19D00 (SHR RAM starts offset +$2000)
cur_pal_num = scb & 0x0F
pal_offset = 0x7E00+(cur_pal_num*16*2) # each pal is 16 colors * 2 bytes per color
# now make a dict of each index => (r,g,b) tuple
@digarok
digarok / c1-to-png.py
Created April 10, 2020 15:02
Convert Apple IIgs SHR (Super Hi-Res) images to PNG files
### c1-to-png.py by Dagen Brock
#
# Example: python c1-to-png.py. mypicture.shr output.png
#
from PIL import Image, ImageDraw # `pip3 install pillow` if you don't have it
from sys import argv
def get_scanline_palette(scanline):
scb = shr_buffer[0x7D00+scanline] # SCBs start at $E19D00 (SHR RAM starts offset +$2000)
@digarok
digarok / c1-striper.py
Created March 14, 2020 16:36
This takes a raw Apple IIgs $C1 image and writes zeros to every other "scanline".
# Invoke like:
# $ python stripe.py example.c1 output_dir
from sys import argv
from array import array
import os
data = array('B')
with open(argv[1], 'rb') as input_img: