Guest User

Untitled

a guest
Apr 4th, 2010
370
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /* This is the basic class for all memory banks */
  2.     public abstract static class Bank {
  3.         public final int number;
  4.         public Bank next;
  5.        
  6.        
  7.         /* Constructor */
  8.         public Bank(int number) {
  9.             this.number = number;
  10.         }
  11.        
  12.        
  13.         /* These three functions should be overridden in subclasses */
  14.         /* The addresses must be in the range 0x0000 to 0xFFFF */
  15.         public abstract int readByte(int addr);
  16.         public abstract int peekByte(int addr);
  17.         public abstract void writeByte(int addr, int value);
  18.        
  19.        
  20.         // The address must be in the range 0x0000 to 0x1FFFF.
  21.         // The byte can be in the next bank.
  22.         public final int readByteCarry(int addr) {
  23.             return (addr <= 0xFFFF) ? readByte(addr) : next.readByte(addr & 0xFFFF);
  24.         }
  25.        
  26.         // The address must be in the range 0x0000 to 0xFFFF.
  27.         // The second byte can wrap within the bank.
  28.         public int readShort(int addr) {
  29.             return (
  30.                 (readByte(addr)) |
  31.                 (readByte((addr + 1) & 0xFFFF) << 8)
  32.             );
  33.         }
  34.        
  35.         // The address must be in the range 0x0000 to 0xFFFF.
  36.         // The second byte can carry to the next bank.
  37.         public final int readShortCarryEdge(int addr) {
  38.             if (MORE_ACCURATE_EMULATION) {
  39.                 int low = readByte(addr);
  40.                 int high = (addr != 0xFFFF) ? readByte(addr + 1) : next.readByte(0x0000);
  41.                 return low | (high << 8);
  42.             } else {
  43.                 return readShort(addr);
  44.             }
  45.         }
  46.        
  47.         // The address must be in the range 0x0000 to 0x1FFFE.
  48.         // Both bytes can carry to the next bank.
  49.         public final int readShortCarryFull(int addr) {
  50.             int low = (addr <= 0xFFFF) ? readByte(addr) : next.readByte(addr & 0xFFFF);
  51.             int high = (addr <= 0xFFFE) ? readByte(addr + 1) : next.readByte((addr + 1) & 0xFFFF);
  52.             return low | (high << 8);
  53.         }
  54.        
  55.         // The address must be in the range 0x0000 to 0xFFFF.
  56.         // The second and third bytes can wrap within the bank.
  57.         public final int readMedium(int addr) {
  58.             int low = readByte(addr);
  59.             int medium = readByte((addr + 1) & 0xFFFF);
  60.             int high = readByte((addr + 2) & 0xFFFF);
  61.             return low | (medium << 8) | (high << 16);
  62.         }
  63.        
  64.         // The address must be in the range 0x0000 to 0x1FFFF.
  65.         // The byte can be in the next bank.
  66.         public final void writeByteCarry(int addr, int value) {
  67.             if (addr <= 0xFFFF) {
  68.                 writeByte(addr, value);
  69.             } else {
  70.                 next.writeByte(addr & 0xFFFF, value);
  71.             }
  72.         }
  73.        
  74.         // The address must be in the range 0x0000 to 0xFFFF.
  75.         // The second byte can wrap within the bank.
  76.         public void writeShort(int addr, int value) {
  77.             writeByte(addr, value & 0xFF);
  78.             writeByte((addr + 1) & 0xFFFF, value >> 8);
  79.         }
  80.        
  81.         // The address must be in the range 0x0000 to 0xFFFF.
  82.         // The second byte can carry to the next bank.
  83.         public final void writeShortCarryEdge(int addr, int value) {
  84.             if (MORE_ACCURATE_EMULATION) {
  85.                 writeByte(addr, value & 0xFF);
  86.                 if (addr != 0xFFFF) {
  87.                     writeByte(addr + 1, value >> 8);
  88.                 } else {
  89.                     next.writeByte(0x0000, value >> 8);
  90.                 }
  91.             } else {
  92.                 writeShort(addr, value);
  93.             }
  94.         }
  95.        
  96.         // The address must be in the range 0x0000 to 0x1FFFE.
  97.         // Both bytes can carry to the next bank.
  98.         public final void writeShortCarryFull(int addr, int value) {
  99.             if (addr < 0xFFFF) {
  100.                 writeShort(addr, value);
  101.             } else if (addr == 0xFFFF) {
  102.                 writeByte(addr, value & 0xFF);
  103.                 next.writeByte(0x0000, value >> 8);
  104.             } else {
  105.                 next.writeShort(addr & 0xFFFF, value);
  106.             }
  107.         }
  108.     }
RAW Paste Data