| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
static void imp() { |
| 16 |
} |
| 17 |
|
| 18 |
static void imp8() { |
| 19 |
} |
| 20 |
|
| 21 |
static void acc() { |
| 22 |
addressing_is_acc = true; |
| 23 |
} |
| 24 |
|
| 25 |
static void imm8() { |
| 26 |
ea = addr_with_k(regs.pc++); |
| 27 |
} |
| 28 |
|
| 29 |
static void immm() { |
| 30 |
ea = addr_with_k(regs.pc++); |
| 31 |
|
| 32 |
if (memory_16bit()) { |
| 33 |
regs.pc++; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
static void immx() { |
| 38 |
ea = addr_with_k(regs.pc++); |
| 39 |
|
| 40 |
if (index_16bit()) { |
| 41 |
regs.pc++; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
static void imm16() { |
| 46 |
ea = addr_with_k(regs.pc); |
| 47 |
regs.pc += 2; |
| 48 |
} |
| 49 |
|
| 50 |
static void _zp_with_offset(uint16_t offset) { |
| 51 |
uint16_t imm_value = (uint16_t) read6502((uint16_t)regs.pc++, regs.k); |
| 52 |
|
| 53 |
if (regs.dp & 0x00FF) { |
| 54 |
penaltyd = 1; |
| 55 |
} |
| 56 |
|
| 57 |
ea = direct_page_add(imm_value + offset); |
| 58 |
} |
| 59 |
|
| 60 |
static void _zp_long_with_offset(uint16_t offset) { |
| 61 |
uint16_t eahelp; |
| 62 |
eahelp = (uint16_t)read6502(regs.pc++, regs.k); |
| 63 |
|
| 64 |
ea = (uint32_t)read6502(direct_page_add(eahelp), 0) | ((uint32_t)read6502(direct_page_add(eahelp + 1), 0) << 8) | ((uint32_t)read6502(direct_page_add(eahelp + 2), 0) << 16); |
| 65 |
ea = mask_long_addr(ea + offset); |
| 66 |
|
| 67 |
if (regs.dp & 0x00FF) { |
| 68 |
penaltyd = 1; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static void zp() { |
| 73 |
_zp_with_offset(0); |
| 74 |
} |
| 75 |
|
| 76 |
static void zpx() { |
| 77 |
_zp_with_offset(regs.x); |
| 78 |
} |
| 79 |
|
| 80 |
static void zpy() { |
| 81 |
_zp_with_offset(regs.y); |
| 82 |
} |
| 83 |
|
| 84 |
static void rel() { |
| 85 |
reladdr = (uint16_t)read6502(regs.pc++, regs.k); |
| 86 |
if (reladdr & 0x80) reladdr |= 0xFF00; |
| 87 |
} |
| 88 |
|
| 89 |
static void rel16() { |
| 90 |
reladdr = (uint16_t)read6502(regs.pc, regs.k) | ((uint16_t)read6502(regs.pc+1, regs.k) << 8); |
| 91 |
regs.pc += 2; |
| 92 |
} |
| 93 |
|
| 94 |
static void abso() { |
| 95 |
ea = addr_with_db((uint16_t) read6502(regs.pc, regs.k) | ((uint16_t)read6502(regs.pc+1, regs.k) << 8)); |
| 96 |
regs.pc += 2; |
| 97 |
} |
| 98 |
|
| 99 |
static void absl() { |
| 100 |
ea = (uint32_t) read6502(regs.pc, regs.k) | ((uint32_t)read6502(regs.pc+1, regs.k) << 8) | ((uint32_t)read6502(regs.pc+2, regs.k) << 16); |
| 101 |
regs.pc += 3; |
| 102 |
} |
| 103 |
|
| 104 |
static void absx() { |
| 105 |
uint32_t startpage; |
| 106 |
ea = addr_with_db((uint16_t)read6502(regs.pc, regs.k) | ((uint16_t)read6502(regs.pc+1, regs.k) << 8)); |
| 107 |
startpage = ea & 0xFFFF00; |
| 108 |
ea = mask_long_addr(ea + regs.x); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
if (index_16bit() || startpage != (ea & 0xFFFF00)) { |
| 116 |
penaltyaddr = 1; |
| 117 |
} |
| 118 |
|
| 119 |
regs.pc += 2; |
| 120 |
} |
| 121 |
|
| 122 |
static void abslx() { |
| 123 |
ea = (uint32_t)read6502(regs.pc, regs.k) | ((uint32_t)read6502(regs.pc+1, regs.k) << 8) | ((uint32_t)read6502(regs.pc+2, regs.k) << 16); |
| 124 |
ea = mask_long_addr(ea + regs.x); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
regs.pc += 3; |
| 130 |
} |
| 131 |
|
| 132 |
static void absy() { |
| 133 |
uint32_t startpage; |
| 134 |
ea = addr_with_db((uint16_t)read6502(regs.pc, regs.k) | ((uint16_t)read6502(regs.pc+1, regs.k) << 8)); |
| 135 |
startpage = ea & 0xFFFF00; |
| 136 |
ea = mask_long_addr(ea + regs.y); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
if (index_16bit() || startpage != (ea & 0xFFFF00)) { |
| 144 |
penaltyaddr = 1; |
| 145 |
} |
| 146 |
|
| 147 |
regs.pc += 2; |
| 148 |
} |
| 149 |
|
| 150 |
static void ind() { |
| 151 |
uint16_t eahelp, eahelp2; |
| 152 |
eahelp = (uint16_t)read6502(regs.pc, regs.k) | (uint16_t)((uint16_t)read6502(regs.pc+1, regs.k) << 8); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
eahelp2 = (eahelp+1) & 0xFFFF; |
| 158 |
ea = (uint16_t)read6502(eahelp, 0) | ((uint16_t)read6502(eahelp2, 0) << 8); |
| 159 |
regs.pc += 2; |
| 160 |
} |
| 161 |
|
| 162 |
static void aindl() { |
| 163 |
uint16_t eahelp, eahelp2; |
| 164 |
eahelp = (uint16_t)read6502(regs.pc, regs.k) | (uint16_t)((uint16_t)read6502(regs.pc+1, regs.k) << 8); |
| 165 |
eahelp2 = (eahelp+1) & 0xFFFF; |
| 166 |
ea = (uint32_t)read6502(eahelp, 0) | ((uint32_t)read6502(eahelp2, 0) << 8) | ((uint16_t)read6502((eahelp2 + 1) & 0xFFFF, 0) << 16); |
| 167 |
regs.pc += 2; |
| 168 |
} |
| 169 |
|
| 170 |
static void ind0() { |
| 171 |
uint16_t eahelp; |
| 172 |
eahelp = (uint16_t)read6502(regs.pc++, regs.k); |
| 173 |
|
| 174 |
|
| 175 |
ea = addr_with_db((uint16_t)read6502(direct_page_add(eahelp), 0) | ((uint16_t)read6502(direct_page_add(eahelp + 1), 0) << 8)); |
| 176 |
|
| 177 |
if (regs.dp & 0x00FF) { |
| 178 |
penaltyd = 1; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
static void indl0() { |
| 183 |
_zp_long_with_offset(0); |
| 184 |
} |
| 185 |
|
| 186 |
static void indx() { |
| 187 |
uint16_t eahelp; |
| 188 |
eahelp = (uint16_t)read6502(regs.pc++, regs.k) + regs.x; |
| 189 |
ea = addr_with_db((uint16_t)read6502(direct_page_add(eahelp), 0) | ((uint16_t)read6502(direct_page_add(eahelp + 1), 0) << 8)); |
| 190 |
|
| 191 |
if (regs.dp & 0x00FF) { |
| 192 |
penaltyd = 1; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
static void indy() { |
| 197 |
uint16_t eahelp; |
| 198 |
eahelp = (uint16_t)read6502(regs.pc++, regs.k); |
| 199 |
uint16_t pointer = (uint16_t)read6502(direct_page_add(eahelp), 0) | ((uint16_t)read6502(direct_page_add(eahelp + 1), 0) << 8); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
uint32_t startpage = addr_with_db(pointer) & 0xFFFF00; |
| 204 |
ea = mask_long_addr(addr_with_db(pointer) + regs.y); |
| 205 |
|
| 206 |
if (regs.dp & 0x00FF) { |
| 207 |
penaltyd = 1; |
| 208 |
} |
| 209 |
|
| 210 |
if (index_16bit() || startpage != (ea & 0xFFFF00)) { |
| 211 |
penaltyaddr = 1; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
static void indly() { |
| 216 |
_zp_long_with_offset(regs.y); |
| 217 |
} |
| 218 |
|
| 219 |
static void ind0p() { |
| 220 |
uint16_t eahelp; |
| 221 |
eahelp = (uint16_t)read6502(regs.pc++, regs.k); |
| 222 |
ea = (uint16_t)read6502(regs.dp + eahelp, 0) | ((uint16_t)read6502(regs.dp + eahelp + 1, 0) << 8); |
| 223 |
|
| 224 |
if (regs.dp & 0x00FF) { |
| 225 |
penaltyd = 1; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
static void zprel() { |
| 230 |
ea = (uint16_t)read6502(regs.pc, 0); |
| 231 |
reladdr = (uint16_t)read6502(regs.pc+1, 0); |
| 232 |
if (reladdr & 0x80) reladdr |= 0xFF00; |
| 233 |
|
| 234 |
regs.pc += 2; |
| 235 |
} |
| 236 |
|
| 237 |
static void sr() { |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
ea = (uint16_t)(regs.sp + (uint16_t)read6502(regs.pc++, regs.k)); |
| 242 |
} |
| 243 |
|
| 244 |
static void sridy() { |
| 245 |
uint16_t eahelp; |
| 246 |
eahelp = regs.sp + (uint16_t)read6502(regs.pc++, regs.k); |
| 247 |
uint16_t pointer = (uint16_t)read6502(eahelp, 0) | ((uint16_t)read6502(eahelp + 1, 0) << 8); |
| 248 |
ea = mask_long_addr(addr_with_db(pointer) + (uint16_t)regs.y); |
| 249 |
|
| 250 |
|
| 251 |
} |
| 252 |
|
| 253 |
static void bmv() { |
| 254 |
uint8_t dest = read6502(regs.pc++, regs.k); |
| 255 |
ea = (read6502(regs.pc++, regs.k) << 8) | dest; |
| 256 |
} |