public final void addressWrite(int addr, int data) {
		int ramAddress = 0;


		switch (cartType) {

		case 0 : /* ROM Only */
			break;

		case 1 : /* MBC1 */
		case 2 :
		case 3 :
			if ((addr >= 0xA000) && (addr <= 0xBFFF)) {
				if (ramEnabled) {
					ramAddress = addr - 0xA000 + ramPageStart;
					ram[ramAddress] = (byte) data;
				}
			} if ((addr >= 0x2000) && (addr <= 0x3FFF)) {
				int bankNo = data & 0x1F;
				if (bankNo == 0) bankNo = 1;
				mapRom((currentBank & 0x60) | bankNo);
			} else if ((addr >= 0x6000) && (addr <= 0x7FFF)) {
				if ((data & 1) == 1) {
					mbc1LargeRamMode = true;
					//      ram = new byte[0x8000];
				} else {
					mbc1LargeRamMode = false;
					//      ram = new byte[0x2000];
				}
			} else if (addr <= 0x1FFF) {
				if ((data & 0x0F) == 0x0A) {
					ramEnabled = true;
				} else {
					ramEnabled = false;
				}
			} else if ((addr <= 0x5FFF) && (addr >= 0x4000)) {
				if (mbc1LargeRamMode) {
					ramBank = (data & 0x03);
					ramPageStart = ramBank * 0x2000;
					//      System.out.println("RAM bank " + ramBank + " selected!");
				} else {
					mapRom((currentBank & 0x1F) | ((data & 0x03) << 5));
				}
			}
			break;

		case 5 :
		case 6 :
			if ((addr >= 0x2000) && (addr <= 0x3FFF) && ((addr & 0x0100) != 0) ) {
				int bankNo = data & 0x1F;
				if (bankNo == 0) bankNo = 1;
				mapRom(bankNo);
			}
			if ((addr >= 0xA000) && (addr <= 0xBFFF)) {
				if (ramEnabled) ram[addr - 0xA000 + ramPageStart] = (byte) data;
			}

			break;

		case 0x0F :
		case 0x10 :
		case 0x11 :
		case 0x12 :
		case 0x13 :	/* MBC3 */

			// Select ROM bank
			if ((addr >= 0x2000) && (addr <= 0x3FFF)) {
				int bankNo = data & 0x7F;
				if (bankNo == 0) bankNo = 1;
				mapRom(bankNo);
			} else if ((addr <= 0x5FFF) && (addr >= 0x4000)) {
				// Select RAM bank
				ramBank = data;

				if (ramBank < 0x04) {
					ramPageStart = ramBank * 0x2000;
				}
				//     System.out.println("RAM bank " + ramBank + " selected!");
			} 
			if ((addr >= 0xA000) && (addr <= 0xBFFF)) {
				// Let the game write to RAM
				if (ramBank <= 0x03) {
					ram[addr - 0xA000 + ramPageStart] = (byte) data;
				} else {
					// Write to realtime clock registers
					RTCReg[ramBank - 0x08] = data;
					//     System.out.println("RTC Reg " + ramBank + " = " + data);
				}

			}
			/*	if ((addr >= 0x6000) && (addr <= 0x7FFF)) {
     if ((data & 1) == 1) {
      mbc1LargeRamMode = true;
      System.out.println("Small Ram");
//      ram = new byte[0x8000];
     } else {
      mbc1LargeRamMode = false;
      System.out.println("Large Ram");
//      ram = new byte[0x2000];
     }
	}*/

			break;


		case 0x19 :
		case 0x1A :
		case 0x1B :
		case 0x1C :
		case 0x1D :
		case 0x1E :

			if ((addr >= 0x2000) && (addr <= 0x2FFF)) {
				int bankNo = (currentBank & 0xFF00) | data;
				mapRom(bankNo);
			}
			if ((addr >= 0x3000) && (addr <= 0x3FFF)) {
				int bankNo = (currentBank & 0x00FF) | ((data & 0x01) << 8);
				mapRom(bankNo);
			}

			if ((addr >= 0x4000) && (addr <= 0x5FFF)) {
				ramBank = (data & 0x07);
				ramPageStart = ramBank * 0x2000;
				//     System.out.println("RAM bank " + ramBank + " selected!");
			}
			if ((addr >= 0xA000) && (addr <= 0xBFFF)) {
				ram[addr - 0xA000 + ramPageStart] = (byte) data;
			}
			break;


		}

	}