// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: M6502.java
import java.io.PrintStream;
public class M6502
{
private static final int FLAG_C = 1;
private static final int FLAG_Z = 2;
private static final int FLAG_I = 4;
private static final int FLAG_D = 8;
private static final int FLAG_B = 16;
private static final int FLAG_NOTUSED = 32;
private static final int FLAG_V = 64;
private static final int FLAG_N = 128;
public static final int INT_NONE = 0;
public static final int INT_NMI = 1;
public static final int INT_RESET = 2;
public static final int INT_IRQBRK = 3;
private int A;
private int X;
private int Y;
private int P;
private int S;
private int PC;
private int iPeriod;
private int iCount;
CPUMemory memory;
PPU ppu;
private int cycles[] = {
7, 6, 2, 8, 3, 3, 5, 5, 3, 2,
2, 2, 4, 4, 6, 6, 2, 5, 2, 8,
4, 4, 6, 6, 2, 4, 2, 7, 5, 5,
7, 7, 6, 6, 2, 8, 3, 3, 5, 5,
4, 2, 2, 2, 4, 4, 6, 6, 2, 5,
2, 8, 4, 4, 6, 6, 2, 4, 2, 7,
5, 5, 7, 7, 6, 6, 2, 8, 3, 3,
5, 5, 3, 2, 2, 2, 3, 4, 6, 6,
2, 5, 2, 8, 4, 4, 6, 6, 2, 4,
2, 7, 5, 5, 7, 7, 6, 6, 2, 8,
3, 3, 5, 5, 4, 2, 2, 2, 5, 4,
6, 6, 2, 5, 2, 8, 4, 4, 6, 6,
2, 4, 2, 7, 5, 5, 7, 7, 2, 6,
2, 6, 3, 3, 3, 3, 2, 2, 2, 2,
4, 4, 4, 4, 2, 6, 2, 6, 4, 4,
4, 4, 2, 5, 2, 5, 5, 5, 5, 5,
2, 6, 2, 6, 3, 3, 3, 3, 2, 2,
2, 2, 4, 4, 4, 4, 2, 5, 2, 5,
4, 4, 4, 4, 2, 4, 2, 5, 4, 4,
4, 4, 2, 6, 2, 8, 3, 3, 5, 5,
2, 2, 2, 2, 4, 4, 6, 6, 2, 5,
2, 8, 4, 4, 6, 6, 2, 4, 2, 7,
5, 5, 7, 7, 2, 6, 2, 8, 3, 3,
5, 5, 2, 2, 2, 2, 4, 4, 6, 6,
2, 5, 2, 8, 4, 4, 6, 6, 2, 4,
2, 7, 5, 5, 7, 7
};
private int znTable[] = {
2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128
};
public M6502()
{
iPeriod = 115;
}
public void init(NESSystem nessystem)
{
memory = nessystem.mainMemory;
ppu = nessystem.ppu;
}
private final int read(int i)
{
return memory.read(i);
}
private final int readWord(int i)
{
return memory.readWord(i);
}
private final int readCode(int i)
{
return memory.read(i);
}
private final int readCodeWord(int i)
{
return memory.readWord(i);
}
private final void write(int i, int j)
{
memory.write(i, j);
}
private final void writeWord(int i, int j)
{
memory.writeWord(i, j);
}
private final int byImmediate()
{
return readCode(PC++);
}
private final int byAbsolute()
{
int i = readCodeWord(PC);
PC += 2;
return i;
}
private final int byAbsoluteX()
{
return byAbsolute() + X;
}
private final int byAbsoluteY()
{
return byAbsolute() + Y;
}
private final int byZeroPage()
{
return readCode(PC++);
}
private final int byZeroPageX()
{
return byZeroPage() + X & 0xff;
}
private final int byZeroPageY()
{
return byZeroPage() + Y & 0xff;
}
private final int byIndirectX()
{
return readWord(byZeroPageX());
}
private final int byIndirectY()
{
return readWord(byZeroPage()) + Y;
}
private final void checkPageBoundaryCrossing(int i, int j)
{
if(((j ^ i) & 0x100) != 0)
iCount--;
}
private final int byAbsoluteX2()
{
int i = byAbsolute();
int j = i + X;
checkPageBoundaryCrossing(i, j);
return j;
}
private final int byAbsoluteY2()
{
int i = byAbsolute();
int j = i + Y;
checkPageBoundaryCrossing(i, j);
return j;
}
private final int byIndirectY2()
{
int i = readWord(byZeroPage());
int j = i + Y;
checkPageBoundaryCrossing(i, j);
return j;
}
private final void evalZNFlag(int i)
{
P &= 0xffffff7d;
P |= znTable[i];
}
private final int shiftLeft(int i)
{
P &= 0xffffff7c;
P |= i >> 7;
i <<= 1;
i &= 0xff;
P |= znTable[i];
return i;
}
private final int shiftRight(int i)
{
P &= 0xffffff7c;
P |= i & 0x1;
i >>= 1;
P |= znTable[i];
return i;
}
private final int rotateLeft(int i)
{
i <<= 1;
i |= P & 0x1;
P &= 0xffffff7c;
P |= i >> 8;
i &= 0xff;
P |= znTable[i];
return i;
}
private final int rotateRight(int i)
{
int j = P & 0x1;
P &= 0xffffff7c;
P |= i & 0x1;
i >>= 1;
i |= j << 7;
P |= znTable[i];
return i;
}
private final void branch(int i, boolean flag)
{
byte byte0 = (byte)readCode(PC++);
if(((P & i) != 0) == flag)
{
int j = PC + byte0;
checkPageBoundaryCrossing(PC, j);
PC = j;
iCount--;
}
}
private final void push(int i)
{
write(S + 256, i);
S--;
S &= 0xff;
}
private final int pop()
{
S++;
S &= 0xff;
return read(S + 256);
}
private final void pushWord(int i)
{
push(i / 256);
push(i & 0xff);
}
private final int popWord()
{
return pop() + pop() * 256;
}
private final int increment(int i)
{
i = ++i & 0xff;
P &= 0xffffff7d;
P |= znTable[i];
return i;
}
private final int decrement(int i)
{
i = --i & 0xff;
P &= 0xffffff7d;
P |= znTable[i];
return i;
}
private final void operateAdd(int i)
{
int j = P & 0x1;
int k = A + i + j;
P &= 0xffffff3c;
P |= (~(A & i) & (k & i) & 0x80) != 0 ? 0x40 : 0;
P |= k > 255 ? 1 : 0;
A = k & 0xff;
P |= znTable[A];
}
private final void operateSub(int i)
{
int j = ~P & 0x1;
int k = A - i - j;
P &= 0xffffff3c;
P |= (~(A & i) & (k & i) & 0x80)
- 1
- 2
前往页