trunk/src/emu/cpu/ucom4/ucom4op.inc
| r243428 | r243429 | |
| 2 | 2 | |
| 3 | 3 | // internal helpers |
| 4 | 4 | |
| 5 | inline UINT8 ucom4_cpu_device::ram_r() |
| 6 | { |
| 7 | UINT16 address = m_dph << 4 | m_dpl; |
| 8 | return m_data->read_byte(address & m_datamask) & 0xf; |
| 9 | } |
| 10 | |
| 11 | inline void ucom4_cpu_device::ram_w(UINT8 data) |
| 12 | { |
| 13 | UINT16 address = m_dph << 4 | m_dpl; |
| 14 | m_data->write_byte(address & m_datamask, data & 0xf); |
| 15 | } |
| 16 | |
| 17 | void ucom4_cpu_device::pop_stack() |
| 18 | { |
| 19 | m_pc = m_stack[0] & m_prgmask; |
| 20 | for (int i = 0; i < m_stack_levels; i++) |
| 21 | { |
| 22 | m_stack[i] = m_stack[i+1]; |
| 23 | m_stack[i+1] = 0; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | void ucom4_cpu_device::push_stack() |
| 28 | { |
| 29 | for (int i = m_stack_levels-1; i >= 1; i--) |
| 30 | m_stack[i] = m_stack[i-1]; |
| 31 | m_stack[0] = m_pc; |
| 32 | } |
| 33 | |
| 5 | 34 | void ucom4_cpu_device::op_illegal() |
| 6 | 35 | { |
| 7 | 36 | logerror("%s unknown opcode $%02X at $%03X\n", tag(), m_op, m_pc); |
| r243428 | r243429 | |
| 16 | 45 | void ucom4_cpu_device::op_li() |
| 17 | 46 | { |
| 18 | 47 | // LI X: Load ACC with X |
| 19 | | // note: only execute the first one in a sequence of LAI |
| 48 | // note: only execute the first one in a sequence of LI |
| 20 | 49 | if ((m_prev_op & 0xf0) != (m_op & 0xf0)) |
| 21 | 50 | m_acc = m_op & 0x0f; |
| 22 | 51 | } |
| r243428 | r243429 | |
| 24 | 53 | void ucom4_cpu_device::op_lm() |
| 25 | 54 | { |
| 26 | 55 | // LM X: Load ACC with RAM, xor DPh with X |
| 27 | | op_illegal(); |
| 56 | m_acc = ram_r(); |
| 57 | m_dph ^= (m_op & 0x03); |
| 28 | 58 | } |
| 29 | 59 | |
| 30 | 60 | void ucom4_cpu_device::op_ldi() |
| 31 | 61 | { |
| 32 | 62 | // LDI X: Load DP with X |
| 33 | | op_illegal(); |
| 63 | m_dph = m_arg >> 4 & 0xf; |
| 64 | m_dpl = m_arg & 0x0f; |
| 34 | 65 | } |
| 35 | 66 | |
| 36 | 67 | void ucom4_cpu_device::op_ldz() |
| 37 | 68 | { |
| 38 | 69 | // LDZ X: Load DPh with 0, Load DPl with X |
| 39 | | op_illegal(); |
| 70 | m_dph = 0; |
| 71 | m_dpl = m_op & 0x0f; |
| 40 | 72 | } |
| 41 | 73 | |
| 42 | 74 | |
| r243428 | r243429 | |
| 45 | 77 | void ucom4_cpu_device::op_s() |
| 46 | 78 | { |
| 47 | 79 | // S: Store ACC into RAM |
| 48 | | op_illegal(); |
| 80 | ram_w(m_acc); |
| 49 | 81 | } |
| 50 | 82 | |
| 51 | 83 | |
| r243428 | r243429 | |
| 54 | 86 | void ucom4_cpu_device::op_tal() |
| 55 | 87 | { |
| 56 | 88 | // TAL: Transfer ACC to DPl |
| 57 | | op_illegal(); |
| 89 | m_dpl = m_acc; |
| 58 | 90 | } |
| 59 | 91 | |
| 60 | 92 | void ucom4_cpu_device::op_tla() |
| 61 | 93 | { |
| 62 | | // TLA: Transfer |
| 63 | | op_illegal(); |
| 94 | // TLA: Transfer DPl to ACC |
| 95 | m_acc = m_dpl; |
| 64 | 96 | } |
| 65 | 97 | |
| 66 | 98 | |
| r243428 | r243429 | |
| 69 | 101 | void ucom4_cpu_device::op_xm() |
| 70 | 102 | { |
| 71 | 103 | // XM X: Exchange ACC with RAM, xor DPh with X |
| 72 | | op_illegal(); |
| 104 | UINT8 old_acc = m_acc; |
| 105 | m_acc = ram_r(); |
| 106 | ram_w(old_acc); |
| 107 | m_dph ^= (m_op & 0x03); |
| 73 | 108 | } |
| 74 | 109 | |
| 75 | 110 | void ucom4_cpu_device::op_xmi() |
| 76 | 111 | { |
| 77 | 112 | // XMI X: Exchange ACC with RAM, xor DPh with X, Increment DPl, skip next on carry |
| 78 | | op_illegal(); |
| 113 | op_xm(); |
| 114 | m_dpl = (m_dpl + 1) & 0xf; |
| 115 | m_skip = (m_dpl == 0); |
| 79 | 116 | } |
| 80 | 117 | |
| 81 | 118 | void ucom4_cpu_device::op_xmd() |
| 82 | 119 | { |
| 83 | 120 | // XMD X: Exchange ACC with RAM, xor DPh with X, Decrement DPl, skip next on carry |
| 84 | | op_illegal(); |
| 121 | op_xm(); |
| 122 | m_dpl = (m_dpl - 1) & 0xf; |
| 123 | m_skip = (m_dpl == 0xf); |
| 85 | 124 | } |
| 86 | 125 | |
| 87 | 126 | |
| r243428 | r243429 | |
| 89 | 128 | |
| 90 | 129 | void ucom4_cpu_device::op_ad() |
| 91 | 130 | { |
| 92 | | // AD: Add RAM to Acc, skip next on carry |
| 93 | | op_illegal(); |
| 131 | // AD: Add RAM to ACC, skip next on carry |
| 132 | m_acc += ram_r(); |
| 133 | m_skip = ((m_acc & 0x10) != 0); |
| 134 | m_acc &= 0xf; |
| 94 | 135 | } |
| 95 | 136 | |
| 96 | 137 | void ucom4_cpu_device::op_adc() |
| 97 | 138 | { |
| 98 | | // ADC: Add RAM and carry to Acc, store Carry F/F |
| 139 | // ADC: Add RAM and carry to ACC, store Carry F/F |
| 99 | 140 | op_illegal(); |
| 100 | 141 | } |
| 101 | 142 | |
| 102 | 143 | void ucom4_cpu_device::op_ads() |
| 103 | 144 | { |
| 104 | | // ADS: Add RAM and carry to Acc, store Carry F/F, skip next on carry |
| 145 | // ADS: Add RAM and carry to ACC, store Carry F/F, skip next on carry |
| 105 | 146 | op_illegal(); |
| 106 | 147 | } |
| 107 | 148 | |
| 108 | 149 | void ucom4_cpu_device::op_daa() |
| 109 | 150 | { |
| 110 | 151 | // DAA: Add 6 to ACC to adjust decimal for BCD Addition |
| 111 | | op_illegal(); |
| 152 | m_acc = (m_acc + 6) & 0xf; |
| 112 | 153 | } |
| 113 | 154 | |
| 114 | 155 | void ucom4_cpu_device::op_das() |
| 115 | 156 | { |
| 116 | 157 | // DAS: Add 10 to ACC to adjust decimal for BCD Subtraction |
| 117 | | op_illegal(); |
| 158 | m_acc = (m_acc + 10) & 0xf; |
| 118 | 159 | } |
| 119 | 160 | |
| 120 | 161 | |
| r243428 | r243429 | |
| 123 | 164 | void ucom4_cpu_device::op_exl() |
| 124 | 165 | { |
| 125 | 166 | // EXL: Xor ACC with RAM |
| 126 | | op_illegal(); |
| 167 | m_acc ^= ram_r(); |
| 127 | 168 | } |
| 128 | 169 | |
| 129 | 170 | |
| r243428 | r243429 | |
| 132 | 173 | void ucom4_cpu_device::op_cma() |
| 133 | 174 | { |
| 134 | 175 | // CMA: Complement ACC |
| 135 | | op_illegal(); |
| 176 | m_acc ^= 0xf; |
| 136 | 177 | } |
| 137 | 178 | |
| 138 | 179 | void ucom4_cpu_device::op_cia() |
| 139 | 180 | { |
| 140 | 181 | // CIA: Complement ACC, Increment ACC |
| 141 | | op_illegal(); |
| 182 | m_acc = ((m_acc ^ 0xf) + 1) & 0xf; |
| 142 | 183 | } |
| 143 | 184 | |
| 144 | 185 | |
| r243428 | r243429 | |
| 147 | 188 | void ucom4_cpu_device::op_clc() |
| 148 | 189 | { |
| 149 | 190 | // CLC: Reset Carry F/F |
| 150 | | op_illegal(); |
| 191 | m_carry_f = 0; |
| 151 | 192 | } |
| 152 | 193 | |
| 153 | 194 | void ucom4_cpu_device::op_stc() |
| 154 | 195 | { |
| 155 | 196 | // STC: Set Carry F/F |
| 156 | | op_illegal(); |
| 197 | m_carry_f = 1; |
| 157 | 198 | } |
| 158 | 199 | |
| 159 | 200 | void ucom4_cpu_device::op_tc() |
| 160 | 201 | { |
| 161 | 202 | // TC: skip next on Carry F/F |
| 162 | | op_illegal(); |
| 203 | m_skip = (m_carry_f != 0); |
| 163 | 204 | } |
| 164 | 205 | |
| 165 | 206 | |
| r243428 | r243429 | |
| 168 | 209 | void ucom4_cpu_device::op_inc() |
| 169 | 210 | { |
| 170 | 211 | // INC: Increment ACC, skip next on carry |
| 171 | | op_illegal(); |
| 212 | m_acc = (m_acc + 1) & 0xf; |
| 213 | m_skip = (m_acc == 0); |
| 172 | 214 | } |
| 173 | 215 | |
| 174 | 216 | void ucom4_cpu_device::op_dec() |
| 175 | 217 | { |
| 176 | 218 | // DEC: Decrement ACC, skip next on carry |
| 177 | | op_illegal(); |
| 219 | m_acc = (m_acc - 1) & 0xf; |
| 220 | m_skip = (m_acc == 0xf); |
| 178 | 221 | } |
| 179 | 222 | |
| 180 | 223 | void ucom4_cpu_device::op_ind() |
| 181 | 224 | { |
| 182 | 225 | // IND: Increment DPl, skip next on carry |
| 183 | | op_illegal(); |
| 226 | m_dpl = (m_dpl + 1) & 0xf; |
| 227 | m_skip = (m_dpl == 0); |
| 184 | 228 | } |
| 185 | 229 | |
| 186 | 230 | void ucom4_cpu_device::op_ded() |
| 187 | 231 | { |
| 188 | 232 | // DED: Decrement DPl, skip next on carry |
| 189 | | op_illegal(); |
| 233 | m_dpl = (m_dpl - 1) & 0xf; |
| 234 | m_skip = (m_dpl == 0xf); |
| 190 | 235 | } |
| 191 | 236 | |
| 192 | 237 | |
| r243428 | r243429 | |
| 195 | 240 | void ucom4_cpu_device::op_rmb() |
| 196 | 241 | { |
| 197 | 242 | // RMB B: Reset a single bit of RAM |
| 198 | | op_illegal(); |
| 243 | ram_w(ram_r() & ~(1 << (m_op & 0x03))); |
| 199 | 244 | } |
| 200 | 245 | |
| 201 | 246 | void ucom4_cpu_device::op_smb() |
| 202 | 247 | { |
| 203 | 248 | // SMB B: Set a single bit of RAM |
| 204 | | op_illegal(); |
| 249 | ram_w(ram_r() | (1 << (m_op & 0x03))); |
| 205 | 250 | } |
| 206 | 251 | |
| 207 | 252 | void ucom4_cpu_device::op_reb() |
| 208 | 253 | { |
| 209 | 254 | // REB B: Reset a single bit of output port E |
| 255 | m_icount--; |
| 210 | 256 | op_illegal(); |
| 211 | 257 | } |
| 212 | 258 | |
| 213 | 259 | void ucom4_cpu_device::op_seb() |
| 214 | 260 | { |
| 215 | 261 | // SEB B: Set a single bit of output port E |
| 262 | m_icount--; |
| 216 | 263 | op_illegal(); |
| 217 | 264 | } |
| 218 | 265 | |
| r243428 | r243429 | |
| 234 | 281 | void ucom4_cpu_device::op_jmpcal() |
| 235 | 282 | { |
| 236 | 283 | // JMP A: Jump to Address / CAL A: Call Address |
| 237 | | op_illegal(); |
| 284 | if (m_op & 0x08) |
| 285 | push_stack(); |
| 286 | m_pc = (m_op & 0x07) << 8 | m_arg; |
| 238 | 287 | } |
| 239 | 288 | |
| 240 | 289 | void ucom4_cpu_device::op_jcp() |
| 241 | 290 | { |
| 242 | 291 | // JCP A: Jump to Address in current page |
| 243 | | op_illegal(); |
| 292 | m_pc = (m_pc & ~0x3f) | (m_op & 0x3f); |
| 244 | 293 | } |
| 245 | 294 | |
| 246 | 295 | void ucom4_cpu_device::op_jpa() |
| 247 | 296 | { |
| 248 | | // JPA: Jump to (ACC) |
| 249 | | op_illegal(); |
| 297 | // JPA: Jump to (ACC) in current page |
| 298 | m_pc = (m_pc & ~0x3f) | (m_acc << 2); |
| 250 | 299 | } |
| 251 | 300 | |
| 252 | 301 | void ucom4_cpu_device::op_czp() |
| 253 | 302 | { |
| 254 | | // CZP A: Call (Address) |
| 255 | | op_illegal(); |
| 303 | // CZP A: Call Address (short) |
| 304 | push_stack(); |
| 305 | m_pc = (m_op & 0x0f) << 2; |
| 256 | 306 | } |
| 257 | 307 | |
| 258 | 308 | void ucom4_cpu_device::op_rt() |
| 259 | 309 | { |
| 260 | 310 | // RT: Return from subroutine |
| 261 | | op_illegal(); |
| 311 | m_icount--; |
| 312 | pop_stack(); |
| 262 | 313 | } |
| 263 | 314 | |
| 264 | 315 | void ucom4_cpu_device::op_rts() |
| 265 | 316 | { |
| 266 | 317 | // RTS: Return from subroutine, skip next |
| 267 | | op_rt(); |
| 318 | pop_stack(); |
| 268 | 319 | m_skip = true; |
| 269 | 320 | } |
| 270 | 321 | |
| r243428 | r243429 | |
| 274 | 325 | void ucom4_cpu_device::op_ci() |
| 275 | 326 | { |
| 276 | 327 | // CI X: skip next on ACC equals X |
| 277 | | op_illegal(); |
| 328 | m_skip = (m_acc == (m_arg & 0x0f)); |
| 329 | |
| 330 | if ((m_arg & 0xf0) != 0xc0) |
| 331 | logerror("%s CI opcode unexpected upper arg $%02X at $%03X\n", tag(), m_arg & 0xf0, m_pc); |
| 278 | 332 | } |
| 279 | 333 | |
| 280 | 334 | void ucom4_cpu_device::op_cm() |
| 281 | 335 | { |
| 282 | 336 | // CM: skip next on ACC equals RAM |
| 283 | | op_illegal(); |
| 337 | m_skip = (m_acc == ram_r()); |
| 284 | 338 | } |
| 285 | 339 | |
| 286 | 340 | void ucom4_cpu_device::op_cmb() |
| 287 | 341 | { |
| 288 | 342 | // CMB B: skip next on bit(ACC) equals bit(RAM) |
| 289 | | op_illegal(); |
| 343 | UINT8 mask = 1 << (m_op & 0x03); |
| 344 | m_skip = ((m_acc & mask) == (ram_r() & mask)); |
| 290 | 345 | } |
| 291 | 346 | |
| 292 | 347 | void ucom4_cpu_device::op_tab() |
| 293 | 348 | { |
| 294 | 349 | // TAB B: skip next on bit(ACC) |
| 295 | | op_illegal(); |
| 350 | m_skip = ((m_acc & (1 << (m_op & 0x03))) != 0); |
| 296 | 351 | } |
| 297 | 352 | |
| 298 | 353 | void ucom4_cpu_device::op_cli() |
| 299 | 354 | { |
| 300 | 355 | // CLI X: skip next on DPl equals X |
| 301 | | op_illegal(); |
| 356 | m_skip = (m_dpl == (m_arg & 0x0f)); |
| 357 | |
| 358 | if ((m_arg & 0xf0) != 0xe0) |
| 359 | logerror("%s CLI opcode unexpected upper arg $%02X at $%03X\n", tag(), m_arg & 0xf0, m_pc); |
| 302 | 360 | } |
| 303 | 361 | |
| 304 | 362 | void ucom4_cpu_device::op_tmb() |
| 305 | 363 | { |
| 306 | 364 | // TMB B: skip next on bit(RAM) |
| 307 | | op_illegal(); |
| 365 | m_skip = ((ram_r() & (1 << (m_op & 0x03))) != 0); |
| 308 | 366 | } |
| 309 | 367 | |
| 310 | 368 | void ucom4_cpu_device::op_tpa() |
| r243428 | r243429 | |
| 333 | 391 | |
| 334 | 392 | void ucom4_cpu_device::op_ia() |
| 335 | 393 | { |
| 336 | | // IA: x |
| 394 | // IA: Input port A to ACC |
| 337 | 395 | op_illegal(); |
| 338 | 396 | } |
| 339 | 397 | |
| 340 | 398 | void ucom4_cpu_device::op_ip() |
| 341 | 399 | { |
| 342 | | // IP: x |
| 400 | // IP: Input port (DPl) to ACC |
| 343 | 401 | op_illegal(); |
| 344 | 402 | } |
| 345 | 403 | |
| 346 | 404 | void ucom4_cpu_device::op_oe() |
| 347 | 405 | { |
| 348 | | // OE: x |
| 349 | | op_illegal(); |
| 406 | // OE: Output ACC to port E |
| 407 | m_write_e(0, m_acc, 0xff); |
| 350 | 408 | } |
| 351 | 409 | |
| 352 | 410 | void ucom4_cpu_device::op_op() |
| 353 | 411 | { |
| 354 | | // OP: x |
| 412 | // OP: Output ACC to port (DPl) |
| 355 | 413 | op_illegal(); |
| 356 | 414 | } |
| 357 | 415 | |
| 358 | 416 | void ucom4_cpu_device::op_ocd() |
| 359 | 417 | { |
| 360 | | // OCD X: x |
| 418 | // OCD X: Output X to ports C and D |
| 361 | 419 | op_illegal(); |
| 362 | 420 | } |
| 363 | 421 | |