yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
addressing.cc
Go to the documentation of this file.
1#include "app/emu/cpu/cpu.h"
2
3namespace yaze {
4namespace emu {
5
6void Cpu::AdrImp() {
7 // only for 2-cycle implied opcodes
8 CheckInt();
9 if (int_wanted_) {
10 // if interrupt detected in 2-cycle implied/accumulator opcode,
11 // idle cycle turns into read from pc
12 ReadByte((PB << 16) | PC);
13 } else {
14 callbacks_.idle(false);
15 }
16}
17
18uint32_t Cpu::Immediate(uint32_t* low, bool xFlag) {
19 if ((xFlag && GetIndexSize()) || (!xFlag && GetAccumulatorSize())) {
20 *low = (PB << 16) | PC++;
21 return 0;
22 } else {
23 *low = (PB << 16) | PC++;
24 return (PB << 16) | PC++;
25 }
26}
27
28uint32_t Cpu::AdrDpx(uint32_t* low) {
29 uint8_t adr = ReadOpcode();
30 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
31 callbacks_.idle(false);
32 *low = (D + adr + X) & 0xffff;
33 return (D + adr + X + 1) & 0xffff;
34}
35
36uint32_t Cpu::AdrDpy(uint32_t* low) {
37 uint8_t adr = ReadOpcode();
38 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
39 callbacks_.idle(false);
40 *low = (D + adr + Y) & 0xffff;
41 return (D + adr + Y + 1) & 0xffff;
42}
43
44uint32_t Cpu::AdrIdp(uint32_t* low) {
45 uint8_t adr = ReadOpcode();
46 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
47 uint16_t pointer = ReadWord((D + adr) & 0xffff, false);
48 *low = (DB << 16) + pointer;
49 return ((DB << 16) + pointer + 1) & 0xffffff;
50}
51
52uint32_t Cpu::AdrIdy(uint32_t* low, bool write) {
53 uint8_t adr = ReadOpcode();
54 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
55 uint16_t pointer = ReadWord((D + adr) & 0xffff, false);
56 // writing opcode or x = 0 or page crossed: 1 extra cycle
57 if (write || !GetIndexSize() || ((pointer >> 8) != ((pointer + Y) >> 8)))
58 callbacks_.idle(false);
59 *low = ((DB << 16) + pointer + Y) & 0xffffff;
60 return ((DB << 16) + pointer + Y + 1) & 0xffffff;
61}
62
63uint32_t Cpu::AdrIdl(uint32_t* low) {
64 uint8_t adr = ReadOpcode();
65 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
66 uint32_t pointer = ReadWord((D + adr) & 0xffff, false);
67 pointer |= ReadByte((D + adr + 2) & 0xffff) << 16;
68 *low = pointer;
69 return (pointer + 1) & 0xffffff;
70}
71
72uint32_t Cpu::AdrIly(uint32_t* low) {
73 uint8_t adr = ReadOpcode();
74 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
75 uint32_t pointer = ReadWord((D + adr) & 0xffff, false);
76 pointer |= ReadByte((D + adr + 2) & 0xffff) << 16;
77 *low = (pointer + Y) & 0xffffff;
78 return (pointer + Y + 1) & 0xffffff;
79}
80
81uint32_t Cpu::AdrSr(uint32_t* low) {
82 uint8_t adr = ReadOpcode();
83 callbacks_.idle(false);
84 *low = (SP() + adr) & 0xffff;
85 return (SP() + adr + 1) & 0xffff;
86}
87
88uint32_t Cpu::AdrIsy(uint32_t* low) {
89 uint8_t adr = ReadOpcode();
90 callbacks_.idle(false);
91 uint16_t pointer = ReadWord((SP() + adr) & 0xffff, false);
92 callbacks_.idle(false);
93 *low = ((DB << 16) + pointer + Y) & 0xffffff;
94 return ((DB << 16) + pointer + Y + 1) & 0xffffff;
95}
96
97uint32_t Cpu::Absolute(uint32_t* low) {
98 uint16_t adr = ReadOpcodeWord(false);
99 *low = (DB << 16) + adr;
100 return ((DB << 16) + adr + 1) & 0xffffff;
101}
102
103uint32_t Cpu::AdrAbx(uint32_t* low, bool write) {
104 uint16_t adr = ReadOpcodeWord(false);
105 // writing opcode or x = 0 or page crossed: 1 extra cycle
106 if (write || !GetIndexSize() || ((adr >> 8) != ((adr + X) >> 8)))
107 callbacks_.idle(false);
108 *low = ((DB << 16) + adr + X) & 0xffffff;
109 return ((DB << 16) + adr + X + 1) & 0xffffff;
110}
111
112uint32_t Cpu::AdrAby(uint32_t* low, bool write) {
113 uint16_t adr = ReadOpcodeWord(false);
114 // writing opcode or x = 0 or page crossed: 1 extra cycle
115 if (write || !GetIndexSize() || ((adr >> 8) != ((adr + Y) >> 8)))
116 callbacks_.idle(false);
117 *low = ((DB << 16) + adr + Y) & 0xffffff;
118 return ((DB << 16) + adr + Y + 1) & 0xffffff;
119}
120
121uint32_t Cpu::AdrAbl(uint32_t* low) {
122 uint32_t adr = ReadOpcodeWord(false);
123 adr |= ReadOpcode() << 16;
124 *low = adr;
125 return (adr + 1) & 0xffffff;
126}
127
128uint32_t Cpu::AdrAlx(uint32_t* low) {
129 uint32_t adr = ReadOpcodeWord(false);
130 adr |= ReadOpcode() << 16;
131 *low = (adr + X) & 0xffffff;
132 return (adr + X + 1) & 0xffffff;
133}
134
135uint32_t Cpu::AdrDp(uint32_t* low) {
136 uint8_t adr = ReadOpcode();
137 if (D & 0xff) callbacks_.idle(false); // dpr not 0: 1 extra cycle
138 *low = (D + adr) & 0xffff;
139 return (D + adr + 1) & 0xffff;
140}
141
142uint16_t Cpu::DirectPage() {
143 uint8_t dp = ReadOpcode();
144 return D + dp;
145}
146
148 uint8_t operand = ReadOpcode();
149 uint16_t x_by_mode = GetAccumulatorSize() ? X : X & 0xFF;
150 return D + operand + x_by_mode;
151}
152
154 uint8_t operand = ReadOpcode();
155 return (operand + Y) & 0xFF;
156}
157
158uint32_t Cpu::AdrIdx(uint32_t* low) {
159 uint8_t adr = ReadOpcode();
160 if (D & 0xff) callbacks_.idle(false);
161 callbacks_.idle(false);
162 uint16_t pointer = ReadWord((D + adr + X) & 0xffff, false);
163 *low = (DB << 16) + pointer;
164 return ((DB << 16) + pointer + 1) & 0xffffff;
165}
166
168 uint8_t dp = ReadOpcode();
169 uint16_t effective_address = D + dp;
170 return ReadWordLong((0x00 << 0x10) | effective_address);
171}
172
174 uint8_t operand = ReadOpcode();
175 uint16_t indirect_address = D + operand;
176 uint16_t y_by_mode = GetAccumulatorSize() ? Y : Y & 0xFF;
177 uint32_t effective_address = ReadWordLong(indirect_address) + y_by_mode;
178 return effective_address;
179}
180
182 uint8_t sr = ReadOpcode();
183 uint16_t effective_address = SP() + sr;
184 return effective_address;
185}
186
187} // namespace emu
188} // namespace yaze
uint16_t SP() const
Definition cpu.h:718
uint16_t D
Definition cpu.h:68
uint32_t AdrAby(uint32_t *low, bool write)
uint16_t DirectPage()
uint32_t DirectPageIndirectLongIndexedY()
uint32_t AdrAbl(uint32_t *low)
uint32_t AdrIdy(uint32_t *low, bool write)
Definition addressing.cc:52
uint8_t DB
Definition cpu.h:69
uint32_t AdrSr(uint32_t *low)
Definition addressing.cc:81
uint32_t Immediate(uint32_t *low, bool xFlag)
Definition addressing.cc:18
uint16_t X
Definition cpu.h:66
uint16_t DirectPageIndexedY()
uint8_t ReadByte(uint32_t address)
Definition cpu.h:147
uint32_t AdrIdl(uint32_t *low)
Definition addressing.cc:63
uint32_t DirectPageIndirectLong()
uint16_t ReadWord(uint32_t address, uint32_t address_high, bool int_check=false)
Definition cpu.h:148
uint16_t Y
Definition cpu.h:67
uint8_t ReadOpcode()
Definition cpu.h:138
uint32_t AdrAbx(uint32_t *low, bool write)
void CheckInt()
Definition cpu.h:737
uint32_t AdrDp(uint32_t *low)
int GetIndexSize() const
Definition cpu.h:114
uint16_t PC
Definition cpu.h:71
uint32_t AdrIdp(uint32_t *low)
Definition addressing.cc:44
uint32_t AdrDpy(uint32_t *low)
Definition addressing.cc:36
uint8_t PB
Definition cpu.h:70
uint16_t DirectPageIndexedX()
int GetAccumulatorSize() const
Definition cpu.h:113
uint32_t AdrIly(uint32_t *low)
Definition addressing.cc:72
uint32_t ReadWordLong(uint32_t address)
Definition cpu.h:155
uint32_t AdrIdx(uint32_t *low)
uint32_t Absolute(uint32_t *low)
Definition addressing.cc:97
uint32_t AdrAlx(uint32_t *low)
CpuCallbacks callbacks_
Definition cpu.h:784
uint32_t AdrIsy(uint32_t *low)
Definition addressing.cc:88
uint16_t ReadOpcodeWord(bool int_check=false)
Definition cpu.h:140
uint16_t StackRelative()
bool int_wanted_
Definition cpu.h:781
uint32_t AdrDpx(uint32_t *low)
Definition addressing.cc:28
SNES Emulation and debugging tools.
Definition apu.cc:13
Main namespace for the application.
Definition controller.cc:18