Skip to content

Instantly share code, notes, and snippets.

@formicant
formicant / mult_8bit_2reg.py
Last active July 9, 2026 07:44
mult_8bit_2reg.py
from dataclasses import dataclass
from typing import Iterable
@dataclass(frozen=True, slots=True)
class Program:
state: tuple[int, int]
instructions: list[str]
@property
; Converts a two-byte value to BCD
; Works in const time, no jumps
; params: `hl` - word value
; return: `ahl` - 5 digits in BCD
; spoils: `f`, `c`
; time: 454, length: 112
wordToBcd:
IFUSED
; double dabble algorithm
xor a
import numpy as np
from sys import byteorder
_utf32 = 'utf-32-le' if byteorder == 'little' else 'utf-32-be'
_braille_char_base = 0x2800 # U+2800 BRAILLE PATTERN BLANK
_braille_matrix = np.array([
[0x01, 0x08],
comment_char %
escape_char /
% English locale for Antarctica
% Source:
% Address:
% Contact:
% Email:
% Tel:
% Fax:
@formicant
formicant / avt-gcc-test-no-optimizations.asm
Created March 23, 2023 08:07
AVR-GCC test with no optimizations
Disassembly of section .text:
00000000 <cast_to_uint16>:
0: cf 93 push r28
2: df 93 push r29
4: 0f 92 push r0
6: cd b7 in r28, 0x3d ; 61
8: de b7 in r29, 0x3e ; 62
a: 89 83 std Y+1, r24 ; 0x01
c: 89 81 ldd r24, Y+1 ; 0x01
T = TypeVar('T')
K = TypeVar('K')
def group_by(iterable: Iterable[T], key: Callable[[T], K]) -> Dict[K, List[T]]:
groups: Dict[K, List[T]] = {}
for item in iterable:
k = key(item)
if k in groups: groups[k].append(item)
else: groups[k] = [item]
return groups
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Teclado.Common;
namespace Teclado.WinApi
{
public static class Hooks
{
#region Public methods