Table of Contents

Class BankAttribute

Namespace
GB
Assembly
GBSharp.Framework.dll

Places code or read-only data outside the resident 16 KB of the cartridge.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class BankAttribute : Attribute
Inheritance
BankAttribute
Inherited Members

Remarks

A Game Boy maps two 16 KB windows at once: bank 0, which is always present, and one switchable bank. Everything without this attribute lives in bank 0, which is why a program with no banking at all is capped at 32 KB.

The attribute answers one question (should this stay resident?), and the argument answers a second, optional one: which bank. Written without a number, GB# lets the linker place it and then tells you where it went, so you can pin it by writing the number down. Written with one, that is where it goes. Bank 0 is the resident bank, so [Bank(0)] on a member of a banked type forces that one member to stay mapped.

A member's own attribute beats its containing type's, and a type's applies to its methods and its static readonly fields. Mutable statics cannot be banked: they live in work RAM, which is always mapped and is not banked on this hardware.

[Bank(2)]
public static class ForestLevel
{
    [Asset("forest.png")]
    private static TileMap Art;
public static void Load() => Background.Load(Art);

}

Reaching a banked function costs more than a local call: the call goes through a trampoline that saves the current bank, switches, calls and switches back, and the caller's own bank is unmapped for the duration. GB# reports that at the call site so nothing in a frame loop pays it by accident.

Constructors

BankAttribute()

Let the build choose a bank, and report which one it chose.

public BankAttribute()

BankAttribute(int)

Place this in a specific bank. 0 means the resident bank.

public BankAttribute(int bank)

Parameters

bank int

Properties

Bank

The requested bank, or 0 when placement is automatic.

public int Bank { get; }

Property Value

int

IsAutomatic

True when no bank was named and the build picks one.

public bool IsAutomatic { get; }

Property Value

bool