Skip to content

Instantly share code, notes, and snippets.

@iamgreaser
iamgreaser / icomboot.asm
Created July 22, 2014 02:21
COM bootloader for FAT12
; note, I really don't care if you don't include the licence text,
; just use this damn thing and save yourself some pain --@fanzyflani
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; icomboot
; Copyright (c) 2014, fanzyflani
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
@iamgreaser
iamgreaser / gist:5761539adca572365663
Created July 25, 2014 04:39
Am I documenting my code right
static uint32_t color_sse_to_bytes_1(__m128 m)
{
// Introducing a new, novel way of documenting code!
__m128 multiply_by_255 = _mm_mul_ps(m, _mm_set1_ps(255.0f));
__m128i then_convert_to_int = _mm_cvtps_epi32(multiply_by_255);
__m128i pack_once = _mm_packs_epi32(then_convert_to_int, then_convert_to_int);
__m128i pack_again = _mm_packus_epi16(pack_once, pack_once);
int get_the_int_and_return = _mm_cvtsi128_si32(pack_again);
return get_the_int_and_return;
@iamgreaser
iamgreaser / gist:ae0841c8728e76c2dcfb
Created July 29, 2014 00:58
4D axis-aligned tesseract intersection code
float box_crosses(const box_t *box, const v4f_t *p, const v4f_t *vi, int *inside, int *side)
{
// the general idea:
// define the "out" faces to be in the direction of the ray velocity.
// define the "in" faces to be the other faces.
// if the largest "in" face distance is smaller than the smallest "out" face distance,
// return the largest "in" face distance - we've hit the box.
// otherwise, return -1.0f.
// copy vi so we don't mutilate it
@iamgreaser
iamgreaser / gist:03134f915ddd3c6e8bd9
Created August 3, 2014 00:40
4-bit PCM streaming sound driver (GB + MMC5)
;;;
;;; Jump table vector
;;;
.orga $0050
.section "int_timer" force
jp irq_tima
.ends
;;;
@iamgreaser
iamgreaser / gist:a3d36ecdb277d8f9fbc8
Created August 5, 2014 04:53
write 6 tiles in one fell swoop
_scim_update_copy:
push af
push bc
push hl
; Load pointers
ld a, (scim_src_ptr+0)
ld l, a
ld a, (scim_src_ptr+1)
ld h, a
@iamgreaser
iamgreaser / wav2bin.py
Created August 10, 2014 03:52
16-bit stereo to 4-bit mono PCM
import sys, struct
START = 0x002C
DPERIOD = 1000
def dither(y, x):
x %= DPERIOD
if x >= DPERIOD//2:
x = DPERIOD - x
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <math.h>
#include <GL/glew.h>
#include <SDL.h>
@iamgreaser
iamgreaser / gist:dd916321388ab59ce160
Created August 13, 2014 22:20
keypad entry crap
0000: MOV r4, #0x80000000
0004: MOV r1, #0x00000040
0008: LDRB r2, [r1], #1
000C: CMP r2, #0xFF
0010: BEQ 0x00000034
0014: LDRB r0, [r4]
0018: CMP r0, #0xFF
001C: BEQ 0x00000014
0020: CMP r0, r2
0024: BEQ 0x00000004
@iamgreaser
iamgreaser / gist:773f6461f34fceafc7f8
Created August 13, 2014 22:55
keypad entry with "standard kernel"
0000: MOV r1, #0x00000020
0004: LDRB r2, [r1], #1
0008: CMP r2, #0xFF
000C: BEQ unlock_door_and_halt
0010: BL wait_for_key
0014: CMP r0, r2
0018: BNE sound_alarm_and_halt
001C: B 0x00000004
0020: DB 0x03, 0x01, 0x04, 0x01, 0xFF
@iamgreaser
iamgreaser / gist:82350104b56d4fda75ce
Last active August 29, 2015 14:05
CRC32 for ARM, working in emulator
code_beg:
ldr r3, =0xEDB88320
mvn r0, #0x00000000
mov r1, #0x00000000
mov r4, #(code_end - code_beg)>>2
lp_crc_words:
ldr r2, [r1], #4
eor r0, r0, r2
mov r5, #32
lp_crc_bits: