Skip to content

Instantly share code, notes, and snippets.

View ISSOtm's full-sized avatar
🦀
Rewriting RGBDS... In Rust!

Eldred Habert ISSOtm

🦀
Rewriting RGBDS... In Rust!
View GitHub Profile
@ISSOtm
ISSOtm / cpp11.cpp
Created October 11, 2019 10:57
Reassemble a fragmented string for obfuscation
template<typename Ts...>
char * reassembleString(Ts... ts) {
char * fragments[]{ts...};
size_t size = 0;
for(size_t i = 0; i < sizeof...(Ts); i++) {
size += strlen(fragments[i]);
}
char * output = new char[size + 1];
char * ptr = output;
@ISSOtm
ISSOtm / joypad.asm
Created March 26, 2019 00:05
Game Boy joypad-polling routine, featuring tried-and-tested timings (somehow) as well as Up+Down / Left+Right automatic cancelling
ld c, LOW(rP1)
ld a, $20 ; Select D-pad
ld [$ff00+c], a
REPT 6
ld a, [$ff00+c]
ENDR
or $F0 ; Set 4 upper bits (give them consistency)
ld b, a
; Filter impossible D-pad combinations
@ISSOtm
ISSOtm / language_menu.asm
Last active March 30, 2020 18:01
Menu system, designed for Motherboard GB, and ported elsewhere...
SECTION "Language menu header", ROMX
LanguageMenuHeader::
db BANK("Language menu")
dw LanguageMenuInit
db PADF_START | PADF_DOWN | PADF_UP
db 0 ; Prevent repeat press
dw 0, 0, 0, ForceMenuValidation, 0, 0, 0, 0
db 0 ; Previous item
@ISSOtm
ISSOtm / vblank_copy.asm
Created March 31, 2020 17:59
Help me code golf this pls
jr z, .noVRAMTransfer ; This JR is out of range
ld c, a
ldh a, [hConsoleType]
and a
jr z, .GDMA
ld [wSP], sp
ldh a, [hVRAMCopySrc]
ld l, a
ldh a, [hVRAMCopySrc+1]
ld h, a
@ISSOtm
ISSOtm / fade.asm
Last active April 4, 2020 15:47
Palette loading and fading routines for the Game Boy Color
Fadeout::
xor a
ld [wFadeCount], a
ld a, [wFadeSpeed]
add a, a
jr c, FadeOutToBlack
FadeOutToWhite:
ld a, [wFadeSpeed]
and $7F
jr z, .maxSpeed
@ISSOtm
ISSOtm / popslide.asm
Created April 10, 2020 08:00
Sample from a VBlank handler to transfer tiles using "popslide"
push de
ld [wSP], sp
ldh a, [hVRAMCopySrc]
ld l, a
ldh a, [hVRAMCopySrc+1]
ld h, a
ld sp, hl
ldh a, [hVRAMCopyDest]
ld l, a
ldh a, [hVRAMCopyDest+1]
@ISSOtm
ISSOtm / hardest_part_in_lexer.c
Created April 11, 2020 15:54
"@ISSOtm what's the hardest part about the lexer [of RGBDS]?"
#define keepOnGetc(var, handle) \
do { \
(var) = fgetc(handle); \
} while ((var) == EOF && ferror(handle) && errno == EINTR)
/* Pointer to chars to inject in lexer input */
static char const *insertPtr = NULL;
/* TODO: this doesn't handle interactive buffers; should it try to? */
/*
@ISSOtm
ISSOtm / set_data.s
Created April 15, 2020 21:29
Optimized GBDK lib funcs
.include "global.s"
.globl .copy_vram
;; BANKED: checked
.area _BASE
_set_bkg_data::
_set_win_data::
ld d, #0x90
@ISSOtm
ISSOtm / pal_fade.asm
Created August 21, 2020 19:36
Palette fader for GBC
INCLUDE "defines.asm"
SECTION "Palette buffer fading", ROM0
; Applies fade to both palette buffers
;
FadePaletteBuffers::
ld hl, wFadeSteps
dec [hl]
@ISSOtm
ISSOtm / header.asm
Created September 7, 2020 02:15
Most of Secret Project's init code
Reset::
di ; Disable interrupts while we set up
; Kill sound
xor a
ldh [rNR52], a
; Wait for VBlank and turn LCD off
.waitVBlank
ldh a, [rLY]