Table of Contents
banking.h
Functions for switching the active ROM bank on the cartridge.
The 2MB cartridge for the GameTank has a split memory access where part of the flash is always accessible (the boot segment) and the rest is accessed through a movable window. All 16-bit pointers to data in different ROM banks will occupy the same overlapping address range, so the bank switching functions must be used to dictate which bank is actually being accessed.
To make it safer to change ROM banks inside the body of a function without worrying how it affects other code, the Bank Switching API includes a stack data structure that allows the programmer to change ROM banks when needed and then go back to the previous bank that was in use.
Functions
push_rom_bank()
void push_rom_bank();
Push the current ROM bank to the stack, to be returned to later. The default stack size is 8, defined in banking.c
change_rom_bank
void change_rom_bank(unsigned char banknum);
Issue a ROM bank change command by pushing a new bank number to the cartridge's shift register.'
Can be called as many times as needed between push_rom_bank
and pop_rom_bank
, including zero.
pop_rom_bank
void pop_rom_bank();
Removes the last pushed ROM bank from the stack and calls change_rom_bank
to switch to that bank.
Generally every call to push_rom_bank
should be paired with an eventual call to pop_rom_bank
.