-
Notifications
You must be signed in to change notification settings - Fork 0
/
addressingModes.py
86 lines (73 loc) · 2.15 KB
/
addressingModes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from memory import memory
from opcodes import pageBoundaryCycles
def imp(cpu, arg1, arg2):
cpu.PC += 1
return 0
def imm(cpu, arg1, arg2):
cpu.PC += 2
return arg1
def ZP(cpu, arg1, arg2):
cpu.PC += 2
return arg1
def zp(cpu, arg1, arg2):
return memory.read(arg1)
def ZPX(cpu, arg1, arg2):
cpu.PC += 2
return (arg1+cpu.X) & 0xFF
def zpx(cpu, arg1, arg2):
return memory.read(ZPX(cpu,arg1,arg2))
def ZPY(cpu, arg1, arg2):
cpu.PC += 2
return (arg1 + cpu.Y) & 0xFF
def zpy(cpu, arg1, arg2):
return memory.read(ZPY(cpu,arg1,arg2))
def ABS(cpu, arg1, arg2):
cpu.PC += 3
return arg1 + (arg2 << 8)
def abt(cpu, arg1, arg2):
return memory.read(ABS(cpu,arg1,arg2))
def ABX(cpu, arg1, arg2):
addr = arg1 + (arg2 << 8)
cpu.PC += 3
cpu.cycles += pageBoundaryCycles(addr, cpu.X)
return (addr + cpu.X) & 0xFFFF
def abx(cpu, arg1, arg2):
return memory.read(ABX(cpu,arg1,arg2))
def ABY(cpu, arg1, arg2):
addr = arg1 + (arg2 << 8)
cpu.PC += 3
cpu.cycles += pageBoundaryCycles(addr, cpu.Y)
return (addr + cpu.Y) & 0xFFFF
def aby(cpu, arg1, arg2):
return memory.read(ABY(cpu,arg1,arg2))
def ind(cpu, arg1, arg2):
int addrLSB = arg1 + (arg2 << 8)
int addrMSB = ((arg1 + 1) & 0xFF) + (arg2 << 8)
cpu.PC += 3
return memory.read(addrLSB) + (memory.read(addrMSB) << 8)
def INX(cpu, arg1, arg2):
zpAddr = (arg1 + cpu.X) & 0xFF
indirectAddress = memory.read(zpAddress) + (memory.read((zpAddress + 1) & 0xFF) << 8)
cpu.PC += 2
return indirectAddress
def inx(cpu, arg1, arg2):
return memory.read(INX(cpu,arg1,arg2))
def INY(cpu, arg1, arg2):
indirectAddress = memory.read(arg1) + (memory.read((arg1 + 1) & 0xFF) << 8)
cpu.cycles += pageBoundaryCycles(indirectAddress, cpu.Y)
cpu.PC += 2
return (indirectAddress + cpu.Y) & 0xFFFF
def iny(cpu, arg1, arg2):
return memory.read(INY(cpu,arg1,arg2))
def ACC(cpu, arg1, arg2):
cpu.PC += 1
return -1
def acc(cpu, arg1, arg2):
cpu.PC += 1
return cpu.A
def rel(cpu, arg1, arg2):
cpu.PC += 2
offset = arg1
if (offset & 0x7F) is not offset:
offset = (0x7F & offset) - 0x80
return offset