Skip to content

Instantly share code, notes, and snippets.

View tobiasvl's full-sized avatar
🦀
Learning Rust

Tobias V. I. Langhoff tobiasvl

🦀
Learning Rust
View GitHub Profile
@tobiasvl
tobiasvl / get_map_position.asm
Last active August 21, 2018 20:54
Game Boy snippet
get_map_position:
; from a sprite's pixel position, get the BG map address.
; d: Y pixel position
; e: X pixel position
; hl: returned map address
ld h, HIGH(_SCRN0) >> 2
; Y
ld a, [rSCY] ; account for scroll
sub a, 16 ; account for base sprite offset
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tobiasvl
tobiasvl / save_data.lua
Last active August 9, 2018 21:53
Save data in LÖVE
-- initialize a save file holding a `savedata` sequence
function init_savedata()
local info=love.filesystem.getInfo("savedata.lua", "file")
if info then
local data=love.filesystem.read("savedata.lua")
savedata={love.data.unpack("f",data,1)}
else
local file=love.filesystem.newFile("savedata.lua")
local ok,err=file:open("w")
if not ok then
@tobiasvl
tobiasvl / move_demo.p8
Created May 22, 2018 20:14 — forked from shaneriley/move_demo.p8
PICO-8 Movement Demo
pico-8 cartridge // http://www.pico-8.com
version 4
__lua__
player = {}
player.x = 5
player.y = 5
player.sprite = 0
player.speed = 2
function move()
@tobiasvl
tobiasvl / Makefile
Created April 3, 2018 17:20
RGBDS Makefile
# based on http://voidptr.io/blog/2017/01/21/GameBoy.html
# Simple makefile for assembling and linking a GB program.
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
ASM := rgbasm
LINKER := rgblink
FIX := rgbfix
BUILD_DIR := build
PROJECT_NAME ?=
OUTPUT := $(BUILD_DIR)/$(PROJECT_NAME)
@tobiasvl
tobiasvl / to_c_or_not_to_c.md
Last active October 20, 2025 19:40 — forked from ISSOtm/to_c_or_not_to_c.md
Writeup discussing when to use RGBDS or GBDK.

In the past few years, it seems that, as retro gaming has grown in popularity, programming for older platforms has also gained traction. A popular platform is the Game Boy, both for its nostalgia and (relative) ease to program for.

When someone wants to make their own game, one of the first problems they will encounter is picking the tools they will use. There are two main options: either use GBDK (Game Boy Development Kit) and the language C, or RGBDS (Rednex Game Boy Development System) and the Game Boy's assembly language.

The purpose of this document is to provide my insights and experience, and help you make the better choice if you're starting a new project. I will also provide some "good practice" tips, both for C and ASM, if you have already made up your mind or are already using one of these.

Overview

; C000 = Copy of OAM table
InitSpriteDMA::
; copy spritedma routine into hiram
ld hl,SpriteDMA
ld de,$FF80
ld bc,SpriteDMAEnd - SpriteDMA
call mem_Copy
ret
@tobiasvl
tobiasvl / cere-sh.py
Created September 15, 2017 21:59
Cerebrum development shell
#! /local/bin/python
# vim: set fileencoding=utf-8 :
# Generelt oppsett
import rlcompleter
import readline
import code
from mx import DateTime
@tobiasvl
tobiasvl / cerebrum-hacks
Created September 15, 2017 21:50
Instances of "hack" in the Cerebrum source code
Cerebrum/Constants.py:# This is probably a hack that is done to make makedb create and update
Cerebrum/Database.py: # Not sure that this is the proper default, but as a quick hack it
Cerebrum/Database.py: dictionary to the backend's execute(). This hack implies a performance
Cerebrum/Database.py: # Translate Cerebrum-specific hacks ([:]-syntax we love, e.g.). We
Cerebrum/Database.py: The class is a hairy monstrosity of an enormous hack. SQLite does NOT
Cerebrum/Database.py: """SQLite-specific cursor hacks.
Cerebrum/Database.py: # Since sequences are not supported, we have to hack around them
Cerebrum/Database.py: Hmm... a fix of a patch of an extension of a hack. This is badly
Cerebrum/Person.py: # such a more correct change, we'll live with this hack.
Cerebrum/Person.py: :param ret_primary_acc: Hack to make person_id become account_id.
@tobiasvl
tobiasvl / fedora26-crash.log
Last active August 8, 2017 08:03
Fedora 26, gnome-shell segfaults and takes processes with it
Aug 07 21:22:50 rocinante.uio.no systemd[1]: Starting dnf makecache...
Aug 07 21:22:53 rocinante.uio.no dnf[29990]: Fedora 26 - x86_64 - Updates 30 MB/s | 9.5 MB 00:00
Aug 07 21:22:53 rocinante.uio.no dnf[29990]: Last metadata expiration check: 0:00:00 ago on Mon 07 Aug 2017 09:22:53 PM CEST.
Aug 07 21:22:53 rocinante.uio.no dnf[29990]: Metadata cache created.
Aug 07 21:22:54 rocinante.uio.no systemd[1]: Started dnf makecache.
Aug 07 21:22:54 rocinante.uio.no audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-makecache comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=?
Aug 07 21:22:54 rocinante.uio.no audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-makecache comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=?
Aug 07 21:30:01 rocinante.uio.no CROND[30357]: (root) CMD ( systemctl -q is-active cf-execd.service || sy