Day 22 - Mapper 2

Published: 2005-07-22
Updated: 2010-12-19
Author: Mike Huber

Mapper 2

NOTE: This code doesn't work :(, if someone could figure out why I'll be extremely grateful.

I'd imagine that you'd know what a mapper is by now, maybe you've even already figured out how to use a mapper better than me. Either way, today I'll do some simple code showing how to use Mapper 2. Mapper 2 is probably one of the simplest mappers, it's basically a ROM switch. When a Mapper 2 ROM is loaded, the last ROM bank is put at $C000 and the first at $8000. The one at $C000 can't be switched, so naturally Mapper 2 switches the ROM Bank at $8000. To do this we just write the bank number to ROM anywhere from $8000-$FFFF (doesn't matter).

The Code

This code is simple enough, it starts at $C000, jumps to $8000 which then switches the bank and the newly loaded code bank sets a BG color of pink (I just picked an arbitrary number and it turned out to be pink, oh well :) ). It's quite likely I'm not doing something right, so if you find what it is or if you're just reading this to find my silly errors and laugh at them, please let me know!

The code:

;-- CODE START --; .inesmir 0 ;- don't care about mirroring .inesmap 2 ;- Mapper 2!!! .inesprg 4 ;- This might be 2 (I think NESASM.EXE goes by 8kb PRGs, so therefore the 4) .ineschr 0

.bank 3  ; should be the last bank
.org $FFFA
.dw 0
.dw START
.dw 0

.bank 0    ; first bank loaded at $8000
.org $8000
lda #2     ; will switch the bank to .bank 2 down there...
sta $8000 infin:
jmp infin

.bank 1
.org $C000 ; the second 16kb PRG at $C000 START:              ; the startup location (see vector table in bank 3)
jmp $8000

.bank 2
.org $8000 ; another bank that'll get swapped in
lda #0
sta $2000
lda #%00011000
sta $2001      ; this code will enable PPU and put a nice color for
lda #$3F       ; the background
sta $2006
lda #0
sta $2006
lda #$33
sta $2007 label:
jmp label ;-- CODE END --; </code>

One Last Thing

In all seriousness NESASM.EXE is a pain in the left, little pinky toe to use... I had written a fairly good assembly a while back, but it had some limitations that would make it useless for serious coders (labels didn't work in indirect addressing modes, etc...).

If I ever recode that assembler (i.e. get it working fully, hopefully with macros), then I'll switch to it. I must say that I really hate linking and link scripts and all that stuff; I just want to be able to write code and run it.

This Day In Review

The next installment WILL be attributes.

Happy (no, nothing inparticular, just HAPPY!),
-Mike H a.k.a GbaGuy