system/cartridge.js
function( address ) {
		switch( this.mirroring ) {
		case HORIZONTAL:
			if ( address >= 0x400 ) {
				address -= 0x400;
			}
			if ( address >= 0x800 ) {
				address -= 0x400;
			}
			break;
		case VERTICAL:
			address &= 0x07ff;
			break;
		case FOUR_SCREEN:
			// we still don't implement any mappers that support four screen mirrroring
			throw new Error("TODO, four screen mirroring");
		case SINGLE_SCREEN_LOWER:
		case SINGLE_SCREEN_UPPER:
			address &= 0x3ff;

			if ( this.mirroring === 4 ) {
				address += 0x400;
			}
			break;
		}

		return address;
	}
function( address ) {
		switch( this.mirroring ) {
		case HORIZONTAL:
			if ( address >= 0x400 ) {
				address -= 0x400;
			}
			if ( address >= 0x800 ) {
				address -= 0x400;
			}
			break;
		case VERTICAL:
			address &= 0x07ff;
			break;
		case FOUR_SCREEN:
			// we still don't implement any mappers that support four screen mirrroring
			throw new Error("TODO, four screen mirroring");
		case SINGLE_SCREEN_LOWER:
		case SINGLE_SCREEN_UPPER:
			address &= 0x3ff;

			if ( this.mirroring === 4 ) {
				address += 0x400;
			}
			break;
		}

		return address;
	}
function ( address ) { switch ( this . mirroring ) { case HORIZONTAL : if ( address >= 0x400 ) { address -= 0x400 ; } if ( address >= 0x800 ) { address -= 0x400 ; } break ; case VERTICAL : address &= 0x07ff ; break ; case FOUR_SCREEN : // we still don't implement any mappers that support four screen mirrroring throw new Error ( "TODO, four screen mirroring" ) ; case SINGLE_SCREEN_LOWER : case SINGLE_SCREEN_UPPER : address &= 0x3ff ; if ( this . mirroring === 4 ) { address += 0x400 ; } break ; } return address ; }
Map a nametable address to our internal memory, taking mirroring into account.
Map a nametable address to our internal memory taking mirroring into account .