3.1 Banks


GBDK doesnīt supports Memory-BANKS automatically. You have to link them with the compiler. GBDK i.e. canīt split huge data into several roms. You have to handle the BANKS yourself with direct memory adressing.

The best way of handling BANKs is to put all your program-code into BANK(0) and your data-code into BANK (1-31).

 

Using the MBC1 memory bank controller:

#define SWITCH_ROM_MBC1(b) \*(unsigned char *)0x2000 = (b)
SWITCH_ROM_MBC1(b) switches the current changable 16k ROM to the bank specified by b.

#define SWITCH_RAM_MBC1(b) \*(unsigned char *)0x4000 = (b)
SWITCH_RAM_MBC1(b) switches the RAM bank to the bank specified by b.

#define ENABLE_RAM_MBC1 \*(unsigned char *)0x0000 = 0x0A
ENABLE_RAM_MBC1 enables support for external ram.

#define DISABLE_RAM_MBC1 \*(unsigned char *)0x0000 = 0x00
DISABLE_RAM_MBC1 disables support for external ram.


Using the MBC5 memory bank controller:

Note! Using MBC5 and bankswitching seems to have a slight error in the code.

#define SWITCH_ROM_MBC5(b)
\*(unsigned char *)0x2000 = (b)&0xFF; \*(unsigned char *)0x3000 = (b)>>8
SWITCH_ROM_MBC5(b) switches the current changable 16k ROM to the bank specified by b.

#define SWITCH_RAM_MBC5(b) \*(unsigned char *)0x4000 = (b)
SWITCH_RAM_MBC5(b) switches the RAM bank to the bank specified by b.

#define ENABLE_RAM_MBC5 \*(unsigned char *)0x0000 = 0x0A
ENABLE_RAM_MBC1 enables support for external ram.

#define DISABLE_RAM_MBC5 \*(unsigned char *)0x0000 = 0x00
DISABLE_RAM_MBC1 disables support for external ram.

void hiramcpy(UBYTE dst,const void *src,UBYTE n);
hiramcpy copies procedures from ROM to RAM.