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