Skip to content

Instantly share code, notes, and snippets.

def put_16bit(rom,addr,value):
rom[addr] = value & 0xff
rom[addr+1] = (value>>8) & 0xff
def put_16bit_be(rom,addr,value):
rom[addr] = (value>>8) & 0xff
rom[addr+1] = value & 0xff
def patch_rom(in_file,out_file,byte_value):
@nitro2k01
nitro2k01 / asm
Created October 2, 2025 05:48
New SGB_SEND_PACKET that doesn't clobber DE
SGB_SEND_PACKET_new::
ld BC,16+1 ; B=0, C=SGB packet length in bytes, +1 .
xor A ; A=0, also clear carry.
ldh [rP1],A ; Send start bit.
.bitloop
ld A,$30
ldh [rP1],A ; Send idle state.
.bitloop_into
rr B ; Get next bit, plus zero check.
FORMAT: MACRO
ld hl, \1
ld de, \2
ld d, d
jr .end\@
DW $6464
DW $0200
.end\@:
ENDM
@nitro2k01
nitro2k01 / revdpad.asm
Created October 16, 2022 15:53
GB ASM: Reverse the directions of the D pad.
ld B,A ; Store untouched copy DULRSsBA
and $A0 ; Mask out D0L00000
rrca ; Rotate right 0D0L0000
ld C,A ; Store 0D0L0000 for later.
ld A,B ; Restore unmodified copy.
and $F0 ; Mask out DULR0000
add B ; Shift only upper nibble left.
; A DULR0000
; B +DULRSsBA
; =ULR0SsBA
xor a
ldh [$FF40],a ; Disable LCD as early as possible
ld hl,.hram_payload_start
ld c,$80 ; Bottom of HRAM
.copyloop
ldi a,[hl]
ld [$ff00+c],a
inc c
jr nz,.copyloop
jp $FF80
@nitro2k01
nitro2k01 / abs.asm
Created July 10, 2020 03:48
ABS asm rewrite for GBDK
; GBDK abs function
; Original rewrite by JL2210
; int abs(int)
_abs::
; first word is return address
; second is argument
pop hl ; 3
pop de ; 3 make copy of de
push de ; 4 but leave it on the stack for the caller to clean up
ld a, d ; 1
[MENU]
MENUITEM=WIN, Windows
MENUITEM=GRUB, GRUB
[GRUB]
DEVICE=C:\GRUB.EXE
[WIN]
; The original contents of config.sys go here.
from big_ol_pile_of_manim_imports import *
from math import sin
def cos_product_approximation(order):
return lambda x : np.prod([x]+[
np.cos(x/(2**k))
for k in range(1,order+2)
])
class ExampleApproximation(GraphScene):
@nitro2k01
nitro2k01 / int16mem_shiftright7.asm
Created January 22, 2020 12:25
GB ASM int16 >> 7 in memory.
; Input conditions:
; HL contains the upper byte of the 16 bit variable.
; HL+1 contains the lower byte of the 16 bit variable.
LD A,[HL+] ; A now contains the upper byte. HL contains a pointer to the lower byte.
RL [HL] ; Extract the upper bit of the lower byte into the carry flag.
; Pseudo-C: carry = (LOWER & 0x80) ? 1 : 0;
ADC A,A ; ADD A,A is equivalent to a 1 bit left shift.
; ADC A,A (add carry) is equivalent to a 1 bit left shift which also shifts in carry into the lowest bit.
; Pseudo-C: LOWER = (UPPER<<1)|carry;