yaze 0.3.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)
31 callbacks_.idle(false); // dpr not 0: 1 extra cycle
32 callbacks_.idle(false);
33 *low = (D + adr + X) & 0xffff;
34 return (D + adr + X + 1) & 0xffff;
35}
36
37uint32_t Cpu::AdrDpy(uint32_t* low) {
38 uint8_t adr = ReadOpcode();
39 if (D & 0xff)
40 callbacks_.idle(false); // dpr not 0: 1 extra cycle
41 callbacks_.idle(false);
42 *low = (D + adr + Y) & 0xffff;
43 return (D + adr + Y + 1) & 0xffff;
44}
45
46uint32_t Cpu::AdrIdp(uint32_t* low) {
47 uint8_t adr = ReadOpcode();
48 if (D & 0xff)
49 callbacks_.idle(false); // dpr not 0: 1 extra cycle
50 uint16_t pointer = ReadWord((D + adr) & 0xffff);
51 *low = (DB << 16) + pointer;
52 return ((DB << 16) + pointer + 1) & 0xffffff;
53}
54
55uint32_t Cpu::AdrIdy(uint32_t* low, bool write) {
56 uint8_t adr = ReadOpcode();
57 if (D & 0xff)
58 callbacks_.idle(false); // dpr not 0: 1 extra cycle
59 uint16_t pointer = ReadWord((D + adr) & 0xffff);
60 // writing opcode or x = 0 or page crossed: 1 extra cycle
61 if (write || !GetIndexSize() || ((pointer >> 8) != ((pointer + Y) >> 8)))
62 callbacks_.idle(false);
63 *low = ((DB << 16) + pointer + Y) & 0xffffff;
64 return ((DB << 16) + pointer + Y + 1) & 0xffffff;
65}
66
67uint32_t Cpu::AdrIdl(uint32_t* low) {
68 uint8_t adr = ReadOpcode();
69 if (D & 0xff)
70 callbacks_.idle(false); // dpr not 0: 1 extra cycle
71 uint32_t pointer = ReadWord((D + adr) & 0xffff);
72 pointer |= ReadByte((D + adr + 2) & 0xffff) << 16;
73 *low = pointer;
74 return (pointer + 1) & 0xffffff;
75}
76
77uint32_t Cpu::AdrIly(uint32_t* low) {
78 uint8_t adr = ReadOpcode();
79 if (D & 0xff)
80 callbacks_.idle(false); // dpr not 0: 1 extra cycle
81 uint32_t pointer = ReadWord((D + adr) & 0xffff);
82 pointer |= ReadByte((D + adr + 2) & 0xffff) << 16;
83 *low = (pointer + Y) & 0xffffff;
84 return (pointer + Y + 1) & 0xffffff;
85}
86
87uint32_t Cpu::AdrSr(uint32_t* low) {
88 uint8_t adr = ReadOpcode();
89 callbacks_.idle(false);
90 *low = (SP() + adr) & 0xffff;
91 return (SP() + adr + 1) & 0xffff;
92}
93
94uint32_t Cpu::AdrIsy(uint32_t* low) {
95 uint8_t adr = ReadOpcode();
96 callbacks_.idle(false);
97 uint16_t pointer = ReadWord((SP() + adr) & 0xffff);
98 callbacks_.idle(false);
99 *low = ((DB << 16) + pointer + Y) & 0xffffff;
100 return ((DB << 16) + pointer + Y + 1) & 0xffffff;
101}
102
103uint32_t Cpu::Absolute(uint32_t* low) {
104 uint16_t adr = ReadOpcodeWord(false);
105 *low = (DB << 16) + adr;
106 return ((DB << 16) + adr + 1) & 0xffffff;
107}
108
109uint32_t Cpu::AdrAbx(uint32_t* low, bool write) {
110 uint16_t adr = ReadOpcodeWord(false);
111 // writing opcode or x = 0 or page crossed: 1 extra cycle
112 if (write || !GetIndexSize() || ((adr >> 8) != ((adr + X) >> 8)))
113 callbacks_.idle(false);
114 *low = ((DB << 16) + adr + X) & 0xffffff;
115 return ((DB << 16) + adr + X + 1) & 0xffffff;
116}
117
118uint32_t Cpu::AdrAby(uint32_t* low, bool write) {
119 uint16_t adr = ReadOpcodeWord(false);
120 // writing opcode or x = 0 or page crossed: 1 extra cycle
121 if (write || !GetIndexSize() || ((adr >> 8) != ((adr + Y) >> 8)))
122 callbacks_.idle(false);
123 *low = ((DB << 16) + adr + Y) & 0xffffff;
124 return ((DB << 16) + adr + Y + 1) & 0xffffff;
125}
126
127uint32_t Cpu::AdrAbl(uint32_t* low) {
128 uint32_t adr = ReadOpcodeWord(false);
129 adr |= ReadOpcode() << 16;
130 *low = adr;
131 return (adr + 1) & 0xffffff;
132}
133
134uint32_t Cpu::AdrAlx(uint32_t* low) {
135 uint32_t adr = ReadOpcodeWord(false);
136 adr |= ReadOpcode() << 16;
137 *low = (adr + X) & 0xffffff;
138 return (adr + X + 1) & 0xffffff;
139}
140
141uint32_t Cpu::AdrDp(uint32_t* low) {
142 uint8_t adr = ReadOpcode();
143 if (D & 0xff)
144 callbacks_.idle(false); // dpr not 0: 1 extra cycle
145 *low = (D + adr) & 0xffff;
146 return (D + adr + 1) & 0xffff;
147}
148
149uint16_t Cpu::DirectPage() {
150 uint8_t dp = ReadOpcode();
151 return D + dp;
152}
153
155 uint8_t operand = ReadOpcode();
156 uint16_t x_by_mode = GetAccumulatorSize() ? X : X & 0xFF;
157 return D + operand + x_by_mode;
158}
159
161 uint8_t operand = ReadOpcode();
162 return (operand + Y) & 0xFF;
163}
164
165uint32_t Cpu::AdrIdx(uint32_t* low) {
166 uint8_t adr = ReadOpcode();
167 if (D & 0xff)
168 callbacks_.idle(false);
169 callbacks_.idle(false);
170 uint16_t pointer = ReadWord((D + adr + X) & 0xffff);
171 *low = (DB << 16) + pointer;
172 return ((DB << 16) + pointer + 1) & 0xffffff;
173}
174
176 uint8_t dp = ReadOpcode();
177 uint16_t effective_address = D + dp;
178 return ReadWordLong((0x00 << 0x10) | effective_address);
179}
180
182 uint8_t operand = ReadOpcode();
183 uint16_t indirect_address = D + operand;
184 uint16_t y_by_mode = GetAccumulatorSize() ? Y : Y & 0xFF;
185 uint32_t effective_address = ReadWordLong(indirect_address) + y_by_mode;
186 return effective_address;
187}
188
190 uint8_t sr = ReadOpcode();
191 uint16_t effective_address = SP() + sr;
192 return effective_address;
193}
194
195} // namespace emu
196} // namespace yaze
uint16_t SP() const
Definition cpu.h:765
uint16_t D
Definition cpu.h:77
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:55
uint8_t DB
Definition cpu.h:78
uint32_t AdrSr(uint32_t *low)
Definition addressing.cc:87
uint32_t Immediate(uint32_t *low, bool xFlag)
Definition addressing.cc:18
uint16_t ReadWord(uint32_t address)
Definition cpu.h:181
uint16_t X
Definition cpu.h:75
uint16_t DirectPageIndexedY()
uint8_t ReadByte(uint32_t address)
Definition cpu.h:178
uint32_t AdrIdl(uint32_t *low)
Definition addressing.cc:67
uint32_t DirectPageIndirectLong()
uint16_t Y
Definition cpu.h:76
uint8_t ReadOpcode()
Definition cpu.h:168
uint32_t AdrAbx(uint32_t *low, bool write)
void CheckInt()
Definition cpu.h:784
uint32_t AdrDp(uint32_t *low)
int GetIndexSize() const
Definition cpu.h:144
uint16_t PC
Definition cpu.h:80
uint32_t AdrIdp(uint32_t *low)
Definition addressing.cc:46
uint32_t AdrDpy(uint32_t *low)
Definition addressing.cc:37
uint8_t PB
Definition cpu.h:79
uint16_t DirectPageIndexedX()
int GetAccumulatorSize() const
Definition cpu.h:143
uint32_t AdrIly(uint32_t *low)
Definition addressing.cc:77
uint32_t ReadWordLong(uint32_t address)
Definition cpu.h:197
uint32_t AdrIdx(uint32_t *low)
uint32_t Absolute(uint32_t *low)
uint32_t AdrAlx(uint32_t *low)
CpuCallbacks callbacks_
Definition cpu.h:835
uint32_t AdrIsy(uint32_t *low)
Definition addressing.cc:94
uint16_t ReadOpcodeWord(bool int_check=false)
Definition cpu.h:170
uint16_t StackRelative()
bool int_wanted_
Definition cpu.h:831
uint32_t AdrDpx(uint32_t *low)
Definition addressing.cc:28
std::function< void(bool waiting)> idle
Definition memory.h:53