Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This is the basic class for all memory banks */
- public abstract static class Bank {
- public final int number;
- public Bank next;
- /* Constructor */
- public Bank(int number) {
- this.number = number;
- }
- /* These three functions should be overridden in subclasses */
- /* The addresses must be in the range 0x0000 to 0xFFFF */
- public abstract int readByte(int addr);
- public abstract int peekByte(int addr);
- public abstract void writeByte(int addr, int value);
- // The address must be in the range 0x0000 to 0x1FFFF.
- // The byte can be in the next bank.
- public final int readByteCarry(int addr) {
- return (addr <= 0xFFFF) ? readByte(addr) : next.readByte(addr & 0xFFFF);
- }
- // The address must be in the range 0x0000 to 0xFFFF.
- // The second byte can wrap within the bank.
- public int readShort(int addr) {
- return (
- (readByte(addr)) |
- (readByte((addr + 1) & 0xFFFF) << 8)
- );
- }
- // The address must be in the range 0x0000 to 0xFFFF.
- // The second byte can carry to the next bank.
- public final int readShortCarryEdge(int addr) {
- if (MORE_ACCURATE_EMULATION) {
- int low = readByte(addr);
- int high = (addr != 0xFFFF) ? readByte(addr + 1) : next.readByte(0x0000);
- return low | (high << 8);
- } else {
- return readShort(addr);
- }
- }
- // The address must be in the range 0x0000 to 0x1FFFE.
- // Both bytes can carry to the next bank.
- public final int readShortCarryFull(int addr) {
- int low = (addr <= 0xFFFF) ? readByte(addr) : next.readByte(addr & 0xFFFF);
- int high = (addr <= 0xFFFE) ? readByte(addr + 1) : next.readByte((addr + 1) & 0xFFFF);
- return low | (high << 8);
- }
- // The address must be in the range 0x0000 to 0xFFFF.
- // The second and third bytes can wrap within the bank.
- public final int readMedium(int addr) {
- int low = readByte(addr);
- int medium = readByte((addr + 1) & 0xFFFF);
- int high = readByte((addr + 2) & 0xFFFF);
- return low | (medium << 8) | (high << 16);
- }
- // The address must be in the range 0x0000 to 0x1FFFF.
- // The byte can be in the next bank.
- public final void writeByteCarry(int addr, int value) {
- if (addr <= 0xFFFF) {
- writeByte(addr, value);
- } else {
- next.writeByte(addr & 0xFFFF, value);
- }
- }
- // The address must be in the range 0x0000 to 0xFFFF.
- // The second byte can wrap within the bank.
- public void writeShort(int addr, int value) {
- writeByte(addr, value & 0xFF);
- writeByte((addr + 1) & 0xFFFF, value >> 8);
- }
- // The address must be in the range 0x0000 to 0xFFFF.
- // The second byte can carry to the next bank.
- public final void writeShortCarryEdge(int addr, int value) {
- if (MORE_ACCURATE_EMULATION) {
- writeByte(addr, value & 0xFF);
- if (addr != 0xFFFF) {
- writeByte(addr + 1, value >> 8);
- } else {
- next.writeByte(0x0000, value >> 8);
- }
- } else {
- writeShort(addr, value);
- }
- }
- // The address must be in the range 0x0000 to 0x1FFFE.
- // Both bytes can carry to the next bank.
- public final void writeShortCarryFull(int addr, int value) {
- if (addr < 0xFFFF) {
- writeShort(addr, value);
- } else if (addr == 0xFFFF) {
- writeByte(addr, value & 0xFF);
- next.writeByte(0x0000, value >> 8);
- } else {
- next.writeShort(addr & 0xFFFF, value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement