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 / 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 / movement.asm
Created April 23, 2019 11:56
Unexpected behavior with BGB's "run to next line" command
; 1/2
ld hl, wMovementVector + 3
sra [hl]
dec l ; dec hl
rr [hl]
dec l ; dec hl
sra [hl]
dec l ; dec hl
rr [hl]
call .tryMoving
@ISSOtm
ISSOtm / fadein.asm
Created April 24, 2019 20:46
Fade-in and fade-out code for Game Boy, for any palette. Run this every frame.
.fadeIn
ld a, [wCurStateFirstFrame]
and a
jr z, .notFirstFrame
; Assume palettes are properly set (ie. we're fading from the proper solid colors)
; Perform first fade immediately
ld a, 1
ld [wFadeFrames], a
; This is the value that will get added to each color
; It'll be decremented just below
@ISSOtm
ISSOtm / sample_funcs.asm
Last active June 26, 2019 02:32
Prototype for a Game Boy sample player, eventually ended up at https://github.com/ISSOtm/smooth-player
; Here's some technical explanation about Game Boy sample playing:
; The "usual" way of playing sound samples on the Game Boy is to use its wave channel
; Basically, let that channel play its 32 4-bit samples, then refill it
; Problem: to refill the channel, you have to disable it then restart it
; However, when doing so, the "sample buffer" is set to 0 **and not updated**
; This means the channel outputs a spike as its first sample, creating a buzzing sound
;
; Why? That's because of how the Game Boy generates sound: each channel produces
; a digital value between 0 and 15, which is fed to a DAC (Digital to Analog Converter)
@ISSOtm
ISSOtm / script.c
Created September 15, 2019 14:48
Tentative "ad-hoc" linkerscript parser for RGBDS
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "link/main.h"
#include "link/script.h"
#include "link/section.h"
@ISSOtm
ISSOtm / script.c
Created September 16, 2019 00:39
Tentative cleaner (lexer+parser) RGBDS linker script parser
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include "link/main.h"
#include "link/script.h"
#include "link/section.h"
@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 / 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 / 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]