src/emu/cpu/hd61700/hd61700.c
| r0 | r9924 | |
| 1 | /****************************************************************************** |
| 2 | |
| 3 | Hitachi HD61700 cpu core emulation. |
| 4 | by Sandro Ronco |
| 5 | |
| 6 | This CPU core is based on documentations works done by: |
| 7 | - Piotr Piatek ( http://www.pisi.com.pl/piotr433/pb1000he.htm ) |
| 8 | - BLUE ( http://www.geocities.jp/hd61700lab/ ) |
| 9 | |
| 10 | The HD61700 has 0x1800 bytes of internal ROM accessed as 16bit with address |
| 11 | shift by -1 (mapped from 0x0000 to 0x0c00), the external memory is accessed |
| 12 | with a 8bit data bus, this core emulate all memory as 16bit access with |
| 13 | address shifted by -1 and in the memory above 0x0c00 only the lower 8bit |
| 14 | are used. |
| 15 | |
| 16 | TODO: |
| 17 | - dasm don't decode some mnemonics |
| 18 | - CPU fast/slow mode |
| 19 | - probably other minor things |
| 20 | |
| 21 | ******************************************************************************/ |
| 22 | |
| 23 | #include "emu.h" |
| 24 | #include "debugger.h" |
| 25 | #include "hd61700.h" |
| 26 | |
| 27 | // internal ROM |
| 28 | #define INT_ROM 0x0c00 |
| 29 | |
| 30 | // 5 bit registers |
| 31 | #define REG_SX m_regsir[0] |
| 32 | #define REG_SY m_regsir[1] |
| 33 | #define REG_SZ m_regsir[2] |
| 34 | #define READ_SREG(a) (m_regsir[((a)>>5) & 0x03] & 0x1f) |
| 35 | #define WRITE_SREG(a,d) (m_regsir[((a)>>5) & 0x03] = (d) & 0x1f) |
| 36 | |
| 37 | // 8 bit registers |
| 38 | #define REG_PE m_reg8bit[0] |
| 39 | #define REG_PD m_reg8bit[1] |
| 40 | #define REG_IB m_reg8bit[2] |
| 41 | #define REG_UA m_reg8bit[3] |
| 42 | #define REG_IA m_reg8bit[4] |
| 43 | #define REG_IE m_reg8bit[5] |
| 44 | #define REG_TM m_reg8bit[7] |
| 45 | #define READ_REG8(a) (m_reg8bit[(a) & 0x07]) |
| 46 | #define WRITE_REG8(a,d) (m_reg8bit[(a) & 0x07] = d) |
| 47 | |
| 48 | // 16 bit registers |
| 49 | #define REG_IX m_reg16bit[0] |
| 50 | #define REG_IY m_reg16bit[1] |
| 51 | #define REG_IZ m_reg16bit[2] |
| 52 | #define REG_US m_reg16bit[3] |
| 53 | #define REG_SS m_reg16bit[4] |
| 54 | #define REG_KY m_reg16bit[5] |
| 55 | |
| 56 | // main registers |
| 57 | #define READ_REG(a) (m_regmain[(a) & 0x1f]) |
| 58 | #define WRITE_REG(a,d) (m_regmain[(a) & 0x1f] = d) |
| 59 | #define COPY_REG(d,s) (m_regmain[(d) & 0x1f] = m_regmain[(s) & 0x1f]) |
| 60 | #define REG_GET16(r) (((m_regmain[((r)) & 0x1f]<<0)) | (m_regmain[((r) + 1) & 0x1f]<<8)) |
| 61 | #define REG_PUT16(r,d) do{(m_regmain[(r) & 0x1f] = (((d)>>0) & 0xff)); (m_regmain[((r)+1)&0x1f]=(((d)>>8)&0xff));}while(0) |
| 62 | |
| 63 | // opcode |
| 64 | #define GET_REG_IDX(a,b) (((a<<2) & 0x04) | ((b>>5) & 0x03)) |
| 65 | #define RESTORE_REG(o,r,pr) r = (o&0x02) ? r : pr |
| 66 | #define COND_WRITE_REG(o,a,d) if (o&0x08) WRITE_REG(a,d) |
| 67 | #define GET_IM3(d) (((d>>5)&0x07) + 1) |
| 68 | |
| 69 | // flags |
| 70 | #define SET_FLAG_C m_flags |= FLAG_C |
| 71 | #define CLEAR_FLAG_Z m_flags |= FLAG_Z |
| 72 | #define CLEAR_FLAG_LZ m_flags |= FLAG_LZ |
| 73 | #define CLEAR_FLAG_UZ m_flags |= FLAG_UZ |
| 74 | #define CLEAR_FLAGS m_flags &= ~(FLAG_Z | FLAG_C | FLAG_LZ | FLAG_UZ) |
| 75 | |
| 76 | #define CHECK_FLAG_Z(d) if((d) != 0) CLEAR_FLAG_Z |
| 77 | #define CHECK_FLAG_C(d,l) if (d > l) SET_FLAG_C |
| 78 | #define CHECK_FLAGB_LZ(d) if(((d) & 0x0f) != 0) CLEAR_FLAG_LZ |
| 79 | #define CHECK_FLAGB_UZ(d) if(((d) & 0xf0) != 0) CLEAR_FLAG_UZ |
| 80 | #define CHECK_FLAGW_LZ(d) if(((d) & 0x0f00) != 0) CLEAR_FLAG_LZ |
| 81 | #define CHECK_FLAGW_UZ(d) if(((d) & 0xf000) != 0) CLEAR_FLAG_UZ |
| 82 | #define CHECK_FLAGB_UZ_LZ(d) do{CHECK_FLAGB_LZ(d); CHECK_FLAGB_UZ(d);}while(0) |
| 83 | #define CHECK_FLAGW_UZ_LZ(d) do{CHECK_FLAGW_LZ(d); CHECK_FLAGW_UZ(d);}while(0) |
| 84 | |
| 85 | //CPU state |
| 86 | #define CPU_FAST 0x01 |
| 87 | #define CPU_SLP 0x02 |
| 88 | |
| 89 | /* HD61700 IRQ vector */ |
| 90 | static const UINT16 irq_vector[] = {0x0032, 0x0042, 0x0052, 0x0062, 0x0072}; |
| 91 | |
| 92 | //************************************************************************** |
| 93 | // DEVICE DEFINITIONS |
| 94 | //************************************************************************** |
| 95 | |
| 96 | const device_type HD61700 = hd61700_cpu_device_config::static_alloc_device_config; |
| 97 | |
| 98 | |
| 99 | //************************************************************************** |
| 100 | // HD61700 DEVICE CONFIG |
| 101 | //************************************************************************** |
| 102 | |
| 103 | //------------------------------------------------- |
| 104 | // hd61700_cpu_device_config - constructor |
| 105 | //------------------------------------------------- |
| 106 | |
| 107 | hd61700_cpu_device_config::hd61700_cpu_device_config(const machine_config &mconfig, device_type type, const char *tag, const device_config *owner, UINT32 clock) |
| 108 | : cpu_device_config(mconfig, type, "HD61700", tag, owner, clock), |
| 109 | m_program_config("program", ENDIANNESS_BIG, 16, 18, -1) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | |
| 114 | //------------------------------------------------- |
| 115 | // static_alloc_device_config - allocate a new |
| 116 | // configuration object |
| 117 | //------------------------------------------------- |
| 118 | |
| 119 | device_config *hd61700_cpu_device_config::static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ) |
| 120 | { |
| 121 | return global_alloc(hd61700_cpu_device_config(mconfig, HD61700, tag, owner, clock)); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | //------------------------------------------------- |
| 126 | // alloc_device - allocate a new device object |
| 127 | //------------------------------------------------- |
| 128 | |
| 129 | device_t *hd61700_cpu_device_config::alloc_device(running_machine &machine) const |
| 130 | { |
| 131 | return pool_alloc(machine_get_pool(machine), hd61700_cpu_device(machine, *this)); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | //------------------------------------------------- |
| 136 | // static_set_config - set the configuration |
| 137 | // structure |
| 138 | //------------------------------------------------- |
| 139 | |
| 140 | void hd61700_cpu_device_config::static_set_config(device_config *device, const hd61700_config &config) |
| 141 | { |
| 142 | hd61700_cpu_device_config *conf = downcast<hd61700_cpu_device_config *>(device); |
| 143 | *static_cast<hd61700_config *>(conf) = config; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | //************************************************************************** |
| 148 | // HD61700 DEVICE |
| 149 | //************************************************************************** |
| 150 | |
| 151 | //------------------------------------------------- |
| 152 | // hd61700_cpu_device - constructor |
| 153 | //------------------------------------------------- |
| 154 | |
| 155 | hd61700_cpu_device::hd61700_cpu_device(running_machine &machine, const hd61700_cpu_device_config &config) |
| 156 | : cpu_device(machine, config), |
| 157 | m_cpu_config(config) |
| 158 | { |
| 159 | memset(&m_partial_frame_period, 0, sizeof(m_partial_frame_period)); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | //------------------------------------------------- |
| 164 | // device_start - start up the device |
| 165 | //------------------------------------------------- |
| 166 | |
| 167 | void hd61700_cpu_device::device_start() |
| 168 | { |
| 169 | m_program = this->space(AS_PROGRAM); |
| 170 | |
| 171 | m_sec_timer = device_timer_alloc(*this, SEC_TIMER); |
| 172 | timer_adjust_periodic(m_sec_timer, ATTOTIME_IN_SEC(1), 0, ATTOTIME_IN_SEC(1)); |
| 173 | |
| 174 | // save state |
| 175 | state_save_register_device_item(this, 0, m_ppc); |
| 176 | state_save_register_device_item(this, 0, m_curpc); |
| 177 | state_save_register_device_item(this, 0, m_pc); |
| 178 | state_save_register_device_item(this, 0, m_flags); |
| 179 | state_save_register_device_item(this, 0, m_fetch_addr); |
| 180 | state_save_register_device_item(this, 0, m_irq_status); |
| 181 | state_save_register_device_item(this, 0, m_state); |
| 182 | state_save_register_device_item(this, 0, prev_ua); |
| 183 | state_save_register_device_item(this, 0, m_icount); |
| 184 | state_save_register_device_item_array(this, 0, m_regsir); |
| 185 | state_save_register_device_item_array(this, 0, m_reg8bit); |
| 186 | state_save_register_device_item_array(this, 0, m_reg16bit); |
| 187 | state_save_register_device_item_array(this, 0, m_regmain); |
| 188 | state_save_register_device_item_array(this, 0, m_lines_status); |
| 189 | |
| 190 | // register state for debugger |
| 191 | state_add(HD61700_PC, "pc", m_pc).callimport().callexport().formatstr("%04X"); |
| 192 | state_add(HD61700_F, "f", m_flags).callimport().callexport().formatstr("%02X"); |
| 193 | state_add(HD61700_SX, "SX", REG_SX).callimport().callexport().formatstr("%02X"); |
| 194 | state_add(HD61700_SY, "SY", REG_SY).callimport().callexport().formatstr("%02X"); |
| 195 | state_add(HD61700_SZ, "SZ", REG_SZ).callimport().callexport().formatstr("%02X"); |
| 196 | |
| 197 | state_add(HD61700_PE, "pe", REG_PE).callimport().callexport().formatstr("%02X"); |
| 198 | state_add(HD61700_PD, "pd", REG_PD).callimport().callexport().formatstr("%02X"); |
| 199 | state_add(HD61700_IB, "ib", REG_IB).callimport().callexport().formatstr("%02X"); |
| 200 | state_add(HD61700_UA, "ua", REG_UA).callimport().callexport().formatstr("%02X"); |
| 201 | state_add(HD61700_IA, "ia", REG_IA).callimport().callexport().formatstr("%02X"); |
| 202 | state_add(HD61700_IE, "ie", REG_IE).callimport().callexport().formatstr("%02X"); |
| 203 | state_add(HD61700_TM, "tm", REG_TM).callimport().callexport().formatstr("%02X"); |
| 204 | |
| 205 | state_add(HD61700_IX, "ix", REG_IX).callimport().callexport().formatstr("%04X"); |
| 206 | state_add(HD61700_IY, "iy", REG_IY).callimport().callexport().formatstr("%04X"); |
| 207 | state_add(HD61700_IZ, "iz", REG_IZ).callimport().callexport().formatstr("%04X"); |
| 208 | state_add(HD61700_US, "us", REG_US).callimport().callexport().formatstr("%04X"); |
| 209 | state_add(HD61700_SS, "ss", REG_SS).callimport().callexport().formatstr("%04X"); |
| 210 | state_add(HD61700_KY, "ky", REG_KY).callimport().callexport().formatstr("%04X"); |
| 211 | |
| 212 | for (int ireg=0; ireg<32; ireg++) |
| 213 | { |
| 214 | astring tmpstr; |
| 215 | state_add(HD61700_MAINREG + ireg, tmpstr.format("R%d", ireg), m_regmain[ireg]).callimport().callexport().formatstr("%02X"); |
| 216 | } |
| 217 | |
| 218 | state_add(STATE_GENPC, "curpc", m_curpc).callimport().callexport().formatstr("%8s").noshow(); |
| 219 | state_add(STATE_GENPCBASE, "curpcbase", m_ppc).callimport().callexport().formatstr("%8s").noshow(); |
| 220 | state_add(STATE_GENFLAGS, "GENFLAGS", m_flags).mask(0xff).formatstr("%8s").noshow(); |
| 221 | |
| 222 | // set our instruction counter |
| 223 | m_icountptr = &m_icount; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | //------------------------------------------------- |
| 228 | // device_reset - reset up the device |
| 229 | //------------------------------------------------- |
| 230 | |
| 231 | void hd61700_cpu_device::device_reset() |
| 232 | { |
| 233 | m_ppc = 0x0000; |
| 234 | m_curpc = 0x0000; |
| 235 | set_pc(0x0000); |
| 236 | m_flags = FLAG_SW; |
| 237 | m_icount = 0; |
| 238 | m_state = 0; |
| 239 | m_irq_status = 0; |
| 240 | prev_ua = 0; |
| 241 | |
| 242 | memset(m_regsir, 0, ARRAY_LENGTH(m_regsir)); |
| 243 | memset(m_reg8bit, 0, ARRAY_LENGTH(m_reg8bit)); |
| 244 | memset(m_reg16bit, 0, ARRAY_LENGTH(m_reg16bit) * sizeof(UINT16)); |
| 245 | memset(m_regmain, 0, ARRAY_LENGTH(m_regmain)); |
| 246 | |
| 247 | for (int i=0;i<6; i++) |
| 248 | m_lines_status[i] = CLEAR_LINE; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | |
| 253 | //------------------------------------------------- |
| 254 | // device_timer - handler timer events |
| 255 | //------------------------------------------------- |
| 256 | void hd61700_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 257 | { |
| 258 | switch(id) |
| 259 | { |
| 260 | case SEC_TIMER: |
| 261 | REG_TM++; |
| 262 | if ((REG_TM&0x3f) == 60) |
| 263 | { |
| 264 | REG_TM = (REG_TM & 0xc0) + 0x40; |
| 265 | |
| 266 | if (((REG_IE>>3) & (1<<HD61700_TIMER_INT))) |
| 267 | { |
| 268 | REG_IB |= (1<<HD61700_TIMER_INT); |
| 269 | |
| 270 | if (REG_IB & 0x20) |
| 271 | { |
| 272 | m_state &= ~CPU_SLP; |
| 273 | m_flags |= FLAG_APO; |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | |
| 282 | |
| 283 | //------------------------------------------------- |
| 284 | // state_import - import state into the device, |
| 285 | // after it has been set |
| 286 | //------------------------------------------------- |
| 287 | |
| 288 | void hd61700_cpu_device::state_import(const device_state_entry &entry) |
| 289 | { |
| 290 | switch (entry.index()) |
| 291 | { |
| 292 | case HD61700_PC: |
| 293 | set_pc(m_pc); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | //------------------------------------------------- |
| 299 | // state_string_export - export state as a string |
| 300 | // for the debugger |
| 301 | //------------------------------------------------- |
| 302 | |
| 303 | void hd61700_cpu_device::state_string_export(const device_state_entry &entry, astring &string) |
| 304 | { |
| 305 | switch (entry.index()) |
| 306 | { |
| 307 | case STATE_GENFLAGS: |
| 308 | string.printf("%c%c%c%c%c%c", |
| 309 | m_flags & FLAG_Z ? '.' : 'Z', |
| 310 | m_flags & FLAG_C ? 'C' : '.', |
| 311 | m_flags & FLAG_LZ ? '.' : 'L', |
| 312 | m_flags & FLAG_UZ ? '.' : 'U', |
| 313 | m_flags & FLAG_SW ? 'S' : '.', |
| 314 | m_flags & FLAG_APO ? 'A' : '.' |
| 315 | ); |
| 316 | break; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | |
| 322 | //------------------------------------------------- |
| 323 | // disasm_disassemble - call the disassembly |
| 324 | // helper function |
| 325 | //------------------------------------------------- |
| 326 | |
| 327 | offs_t hd61700_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 328 | { |
| 329 | extern CPU_DISASSEMBLE( hd61700 ); |
| 330 | return CPU_DISASSEMBLE_NAME(hd61700)(NULL, buffer, pc, oprom, opram, 0); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | //------------------------------------------------- |
| 336 | // check_irqs - check if need interrupts |
| 337 | //------------------------------------------------- |
| 338 | |
| 339 | bool hd61700_cpu_device::check_irqs(void) |
| 340 | { |
| 341 | for (int i=4; i>=0; i--) |
| 342 | { |
| 343 | if (REG_IB & (1<<i) && !(m_irq_status & (1<<i))) |
| 344 | { |
| 345 | m_irq_status |= (1<<i); |
| 346 | push(REG_SS, (m_pc>>8)&0xff); |
| 347 | push(REG_SS, (m_pc>>0)&0xff); |
| 348 | |
| 349 | set_pc(irq_vector[i]); |
| 350 | m_icount -= 12; |
| 351 | return true; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | //------------------------------------------------- |
| 360 | // execute - execute for the provided number of |
| 361 | // cycles |
| 362 | //------------------------------------------------- |
| 363 | |
| 364 | void hd61700_cpu_device::execute_run() |
| 365 | { |
| 366 | do |
| 367 | { |
| 368 | debugger_instruction_hook(this, m_curpc); |
| 369 | |
| 370 | // verify that CPU is not in sleep |
| 371 | if (m_state & CPU_SLP) |
| 372 | { |
| 373 | m_icount -= 6; |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | UINT8 op; |
| 378 | |
| 379 | check_irqs(); |
| 380 | |
| 381 | m_ppc = m_curpc; |
| 382 | |
| 383 | // instruction fetch |
| 384 | op = read_op(); |
| 385 | |
| 386 | // execute the instruction |
| 387 | switch ( op ) |
| 388 | { |
| 389 | case 0x00: //adc |
| 390 | case 0x01: //sbc |
| 391 | case 0x08: //ad |
| 392 | case 0x09: //sb |
| 393 | { |
| 394 | UINT8 arg = read_op(); |
| 395 | UINT8 src = READ_REG(get_sir_im8(arg)); |
| 396 | UINT16 res = READ_REG(arg) + ((op&1) ? -src : +src); |
| 397 | |
| 398 | COND_WRITE_REG(op, arg, res & 0xff); |
| 399 | |
| 400 | CLEAR_FLAGS; |
| 401 | CHECK_FLAG_Z(res & 0xff); |
| 402 | CHECK_FLAGB_UZ_LZ(res); |
| 403 | CHECK_FLAG_C(res, 0xff); |
| 404 | |
| 405 | check_optional_jr(arg); |
| 406 | m_icount -= 3; |
| 407 | } |
| 408 | break; |
| 409 | |
| 410 | case 0x02: //ld |
| 411 | { |
| 412 | UINT8 arg = read_op(); |
| 413 | COPY_REG(arg, get_sir_im8(arg)); |
| 414 | |
| 415 | check_optional_jr(arg); |
| 416 | m_icount -= 3; |
| 417 | } |
| 418 | break; |
| 419 | |
| 420 | case 0x04: //anc |
| 421 | case 0x05: //nac |
| 422 | case 0x06: //orc |
| 423 | case 0x07: //xrc |
| 424 | case 0x0c: //an |
| 425 | case 0x0d: //na |
| 426 | case 0x0e: //or |
| 427 | case 0x0f: //xr |
| 428 | { |
| 429 | UINT8 arg = read_op(); |
| 430 | |
| 431 | UINT8 res = make_logic(op, READ_REG(arg), READ_REG(get_sir_im8(arg))); |
| 432 | |
| 433 | COND_WRITE_REG(op, arg, res); |
| 434 | |
| 435 | CLEAR_FLAGS; |
| 436 | CHECK_FLAG_Z(res & 0xff); |
| 437 | CHECK_FLAGB_UZ_LZ(res); |
| 438 | |
| 439 | //na(c) and or(c) always set C flag |
| 440 | if ((op&3) == 1 || (op&3) == 2) |
| 441 | SET_FLAG_C; |
| 442 | |
| 443 | check_optional_jr(arg); |
| 444 | m_icount -= 3; |
| 445 | } |
| 446 | break; |
| 447 | |
| 448 | case 0x0a: //adb |
| 449 | case 0x0b: //sbb |
| 450 | { |
| 451 | UINT8 arg = read_op(); |
| 452 | UINT16 res; |
| 453 | |
| 454 | if (op & 0x01) |
| 455 | res = make_bcd_sub(READ_REG(arg), READ_REG(get_sir_im8(arg))); |
| 456 | else |
| 457 | res = make_bcd_add(READ_REG(arg), READ_REG(get_sir_im8(arg))); |
| 458 | |
| 459 | WRITE_REG(arg, res & 0xff); |
| 460 | |
| 461 | CLEAR_FLAGS; |
| 462 | CHECK_FLAG_Z(res & 0xff); |
| 463 | CHECK_FLAGB_UZ_LZ(res); |
| 464 | CHECK_FLAG_C(res, 0xff); |
| 465 | |
| 466 | check_optional_jr(arg); |
| 467 | m_icount -= 3; |
| 468 | } |
| 469 | break; |
| 470 | |
| 471 | case 0x10: //st |
| 472 | { |
| 473 | UINT8 arg = read_op(); |
| 474 | UINT8 src = get_sir_im8(arg); |
| 475 | UINT16 offset = REG_GET16(src); |
| 476 | |
| 477 | mem_writebyte(REG_UA>>4, offset, READ_REG(arg)); |
| 478 | |
| 479 | check_optional_jr(arg); |
| 480 | m_icount -= 8; |
| 481 | } |
| 482 | break; |
| 483 | |
| 484 | case 0x11: //ld |
| 485 | { |
| 486 | UINT8 arg = read_op(); |
| 487 | UINT8 src = get_sir_im8(arg); |
| 488 | UINT16 offset = REG_GET16(src); |
| 489 | |
| 490 | WRITE_REG(arg, mem_readbyte(REG_UA>>4, offset)); |
| 491 | |
| 492 | check_optional_jr(arg); |
| 493 | m_icount -= 8; |
| 494 | } |
| 495 | break; |
| 496 | |
| 497 | case 0x12: //stl |
| 498 | { |
| 499 | UINT8 arg = read_op(); |
| 500 | |
| 501 | if (m_cpu_config.m_lcd_data_w) |
| 502 | (*m_cpu_config.m_lcd_data_w)(*this, READ_REG(arg)); |
| 503 | |
| 504 | check_optional_jr(arg); |
| 505 | m_icount -= 11; |
| 506 | } |
| 507 | break; |
| 508 | |
| 509 | case 0x13: //ldl |
| 510 | { |
| 511 | UINT8 arg = read_op(); |
| 512 | UINT8 res = 0xff; |
| 513 | |
| 514 | if (m_cpu_config.m_lcd_data_r) |
| 515 | res = (*m_cpu_config.m_lcd_data_r)(*this); |
| 516 | |
| 517 | WRITE_REG(arg, res); |
| 518 | |
| 519 | check_optional_jr(arg); |
| 520 | m_icount -= 11; |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | case 0x14: //ppo/pfl |
| 525 | { |
| 526 | UINT8 arg = read_op(); |
| 527 | |
| 528 | if (arg & 0x40) |
| 529 | { |
| 530 | m_flags = (m_flags & 0x0f) | (READ_REG(arg) & 0xf0); |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | if (m_cpu_config.m_lcd_control) |
| 535 | (*m_cpu_config.m_lcd_control)(*this, READ_REG(arg)); |
| 536 | } |
| 537 | |
| 538 | check_optional_jr(arg); |
| 539 | m_icount -= 3; |
| 540 | } |
| 541 | break; |
| 542 | |
| 543 | case 0x15: //psr |
| 544 | { |
| 545 | UINT8 arg = read_op(); |
| 546 | WRITE_SREG(arg, READ_REG(arg)&0x1f); |
| 547 | |
| 548 | check_optional_jr(arg); |
| 549 | m_icount -= 3; |
| 550 | } |
| 551 | break; |
| 552 | |
| 553 | case 0x16: //pst |
| 554 | case 0x17: //pst |
| 555 | { |
| 556 | UINT8 arg = read_op(); |
| 557 | UINT8 src = READ_REG(arg); |
| 558 | UINT8 idx = GET_REG_IDX(op, arg); |
| 559 | |
| 560 | switch (idx) |
| 561 | { |
| 562 | case 0: //PE |
| 563 | case 1: //PD |
| 564 | WRITE_REG8(idx, src); |
| 565 | if (m_cpu_config.m_port_w) |
| 566 | (*m_cpu_config.m_port_w)(*this, REG_PD & REG_PE); |
| 567 | break; |
| 568 | case 2: //IB |
| 569 | REG_IB = (REG_IB & 0x1f) | (src & 0xe0); |
| 570 | break; |
| 571 | case 3: //UA |
| 572 | WRITE_REG8(idx, src); |
| 573 | break; |
| 574 | case 4: //IA |
| 575 | if (m_cpu_config.m_kb_w) |
| 576 | (*m_cpu_config.m_kb_w)(*this, src); |
| 577 | WRITE_REG8(idx, src); |
| 578 | break; |
| 579 | case 5: //IE |
| 580 | REG_IB &= (((src>>3)&0x1f) | 0xe0); |
| 581 | m_irq_status &= ((src>>3)&0x1f); |
| 582 | WRITE_REG8(idx, src); |
| 583 | break; |
| 584 | case 6: //TM |
| 585 | case 7: //TM |
| 586 | // read-only |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | check_optional_jr(arg); |
| 591 | m_icount -= 3; |
| 592 | } |
| 593 | break; |
| 594 | |
| 595 | case 0x18: |
| 596 | { |
| 597 | UINT8 arg = read_op(); |
| 598 | UINT8 op1 = (arg>>5) & 0x03; |
| 599 | switch (op1) |
| 600 | { |
| 601 | case 0x00: //rod |
| 602 | case 0x02: //bid |
| 603 | { |
| 604 | UINT8 src = READ_REG(arg); |
| 605 | UINT8 res = (src>>1)&0x7f; |
| 606 | |
| 607 | if (!(op1&0x02)) |
| 608 | res = res | ((m_flags&FLAG_C) !=0 )<<7; |
| 609 | |
| 610 | WRITE_REG(arg, res); |
| 611 | |
| 612 | CLEAR_FLAGS; |
| 613 | CHECK_FLAG_Z(res & 0xff); |
| 614 | CHECK_FLAGB_UZ_LZ(res); |
| 615 | if (src&0x01) SET_FLAG_C; |
| 616 | } |
| 617 | break; |
| 618 | |
| 619 | case 0x01: //rou |
| 620 | case 0x03: //biu |
| 621 | { |
| 622 | UINT8 src = READ_REG(arg); |
| 623 | UINT8 res = (src<<1)&0xfe; |
| 624 | |
| 625 | if (!(op1&0x02)) |
| 626 | res = res | ((m_flags&FLAG_C) !=0 )<<0; |
| 627 | |
| 628 | WRITE_REG(arg, res); |
| 629 | |
| 630 | CLEAR_FLAGS; |
| 631 | CHECK_FLAG_Z(res & 0xff); |
| 632 | CHECK_FLAGB_UZ_LZ(res); |
| 633 | if (src&0x80) SET_FLAG_C; |
| 634 | } |
| 635 | break; |
| 636 | } |
| 637 | |
| 638 | check_optional_jr(arg); |
| 639 | m_icount -= 3; |
| 640 | } |
| 641 | break; |
| 642 | |
| 643 | case 0x1a: |
| 644 | { |
| 645 | UINT8 arg = read_op(); |
| 646 | UINT8 op1 = (arg>>5) & 0x03; |
| 647 | switch (op1) |
| 648 | { |
| 649 | case 0x00: //did |
| 650 | case 0x01: //diu |
| 651 | { |
| 652 | UINT8 res; |
| 653 | |
| 654 | if (op1&0x01) |
| 655 | res = (READ_REG(arg)<<4)&0xf0; |
| 656 | else |
| 657 | res = (READ_REG(arg)>>4)&0x0f; |
| 658 | |
| 659 | WRITE_REG(arg, res); |
| 660 | |
| 661 | CLEAR_FLAGS; |
| 662 | CHECK_FLAG_Z(res & 0xff); |
| 663 | CHECK_FLAGB_UZ_LZ(res); |
| 664 | } |
| 665 | break; |
| 666 | case 0x02: //byd |
| 667 | case 0x03: //byu |
| 668 | { |
| 669 | WRITE_REG(arg, 0); |
| 670 | CLEAR_FLAGS; |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | check_optional_jr(arg); |
| 676 | m_icount -= 3; |
| 677 | } |
| 678 | break; |
| 679 | |
| 680 | case 0x1b: //cmp/inv |
| 681 | { |
| 682 | UINT8 arg = read_op(); |
| 683 | UINT8 res = ~(READ_REG(arg)); |
| 684 | if (!(arg & 0x40)) res++; |
| 685 | |
| 686 | WRITE_REG(arg, res); |
| 687 | |
| 688 | CLEAR_FLAGS; |
| 689 | CHECK_FLAG_Z(res & 0xff); |
| 690 | CHECK_FLAGB_UZ_LZ(res); |
| 691 | if (res || (arg & 0x40)) SET_FLAG_C; |
| 692 | |
| 693 | check_optional_jr(arg); |
| 694 | m_icount -= 3; |
| 695 | } |
| 696 | break; |
| 697 | |
| 698 | case 0x1c: //gpo/gfl |
| 699 | { |
| 700 | UINT8 arg = read_op(); |
| 701 | UINT8 src = 0xff; |
| 702 | |
| 703 | if (arg&0x40) |
| 704 | { |
| 705 | src = m_flags; |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | if (m_cpu_config.m_port_r) |
| 710 | src = (*m_cpu_config.m_port_r)(*this); |
| 711 | |
| 712 | src&=(~REG_PE); |
| 713 | } |
| 714 | |
| 715 | WRITE_REG(arg, src); |
| 716 | |
| 717 | check_optional_jr(arg); |
| 718 | m_icount -= 3; |
| 719 | } |
| 720 | break; |
| 721 | |
| 722 | case 0x1d: //gsr |
| 723 | { |
| 724 | UINT8 arg = read_op(); |
| 725 | WRITE_REG(arg, READ_SREG(arg)); |
| 726 | check_optional_jr(arg); |
| 727 | m_icount -= 3; |
| 728 | } |
| 729 | break; |
| 730 | |
| 731 | case 0x1e: //gst |
| 732 | case 0x1f: //gst |
| 733 | { |
| 734 | UINT8 arg = read_op(); |
| 735 | UINT8 idx = GET_REG_IDX(op, arg); |
| 736 | WRITE_REG(arg, READ_REG8(idx)); |
| 737 | check_optional_jr(arg); |
| 738 | m_icount -= 3; |
| 739 | } |
| 740 | break; |
| 741 | |
| 742 | case 0x20: //st |
| 743 | case 0x22: //sti |
| 744 | { |
| 745 | UINT8 arg = read_op(); |
| 746 | UINT16 prev_ir = REG_IX; |
| 747 | REG_IX += get_sign_mreg(arg); |
| 748 | |
| 749 | mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg)); |
| 750 | |
| 751 | RESTORE_REG(op, REG_IX, prev_ir); |
| 752 | |
| 753 | m_icount -= 8; |
| 754 | } |
| 755 | break; |
| 756 | |
| 757 | case 0x21: //st |
| 758 | case 0x23: //sti |
| 759 | { |
| 760 | UINT8 arg = read_op(); |
| 761 | UINT16 prev_ir = REG_IZ; |
| 762 | REG_IZ += get_sign_mreg(arg); |
| 763 | |
| 764 | mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg)); |
| 765 | |
| 766 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 767 | |
| 768 | m_icount -= 8; |
| 769 | } |
| 770 | break; |
| 771 | |
| 772 | case 0x24: //std |
| 773 | { |
| 774 | UINT8 arg = read_op(); |
| 775 | REG_IX += get_sign_mreg(arg); |
| 776 | |
| 777 | mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg)); |
| 778 | m_icount -= 6; |
| 779 | } |
| 780 | break; |
| 781 | |
| 782 | case 0x25: //std |
| 783 | { |
| 784 | UINT8 arg = read_op(); |
| 785 | REG_IZ += get_sign_mreg(arg); |
| 786 | |
| 787 | mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg)); |
| 788 | m_icount -= 6; |
| 789 | } |
| 790 | break; |
| 791 | |
| 792 | case 0x26: //phs |
| 793 | { |
| 794 | UINT8 arg = read_op(); |
| 795 | |
| 796 | push(REG_SS, READ_REG(arg)); |
| 797 | m_icount -= 9; |
| 798 | } |
| 799 | break; |
| 800 | case 0x27: //phu |
| 801 | { |
| 802 | UINT8 arg = read_op(); |
| 803 | |
| 804 | push(REG_US, READ_REG(arg)); |
| 805 | m_icount -= 9; |
| 806 | } |
| 807 | break; |
| 808 | |
| 809 | case 0x28: //ld |
| 810 | case 0x2a: //ldi |
| 811 | { |
| 812 | UINT8 arg = read_op(); |
| 813 | UINT16 prev_ir = REG_IX; |
| 814 | REG_IX += get_sign_mreg(arg); |
| 815 | |
| 816 | WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX++)); |
| 817 | |
| 818 | RESTORE_REG(op, REG_IX, prev_ir); |
| 819 | |
| 820 | m_icount -= 8; |
| 821 | } |
| 822 | break; |
| 823 | |
| 824 | case 0x29: //ld |
| 825 | case 0x2b: //ldi |
| 826 | { |
| 827 | UINT8 arg = read_op(); |
| 828 | UINT16 prev_ir = REG_IZ; |
| 829 | REG_IZ += get_sign_mreg(arg); |
| 830 | |
| 831 | WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ++)); |
| 832 | |
| 833 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 834 | |
| 835 | m_icount -= 8; |
| 836 | } |
| 837 | break; |
| 838 | |
| 839 | case 0x2c: //ldd |
| 840 | { |
| 841 | UINT8 arg = read_op(); |
| 842 | REG_IX += get_sign_mreg(arg); |
| 843 | |
| 844 | WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX)); |
| 845 | |
| 846 | m_icount -= 6; |
| 847 | } |
| 848 | break; |
| 849 | |
| 850 | case 0x2d: //ldd |
| 851 | { |
| 852 | UINT8 arg = read_op(); |
| 853 | REG_IZ += get_sign_mreg(arg); |
| 854 | |
| 855 | WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ)); |
| 856 | |
| 857 | m_icount -= 6; |
| 858 | } |
| 859 | break; |
| 860 | |
| 861 | case 0x2e: //pps |
| 862 | { |
| 863 | UINT8 arg = read_op(); |
| 864 | WRITE_REG(arg, pop(REG_SS)); |
| 865 | |
| 866 | m_icount -= 11; |
| 867 | } |
| 868 | break; |
| 869 | case 0x2f: //ppu |
| 870 | { |
| 871 | UINT8 arg = read_op(); |
| 872 | WRITE_REG(arg, pop(REG_US)); |
| 873 | |
| 874 | m_icount -= 11; |
| 875 | } |
| 876 | break; |
| 877 | |
| 878 | case 0x30: //jp z |
| 879 | case 0x31: //jp nc |
| 880 | case 0x32: //jp lz |
| 881 | case 0x33: //jp uz |
| 882 | case 0x34: //jp nz |
| 883 | case 0x35: //jp c |
| 884 | case 0x36: //jp nlz |
| 885 | case 0x37: //unconditional jp |
| 886 | { |
| 887 | UINT8 lsb = read_op(); |
| 888 | if (m_pc < INT_ROM) read_op(); |
| 889 | UINT8 msb = read_op(); |
| 890 | |
| 891 | if (check_cond(op)) |
| 892 | set_pc((msb<<8) | lsb); |
| 893 | m_icount -= 3; |
| 894 | } |
| 895 | break; |
| 896 | |
| 897 | case 0x38: //adc |
| 898 | case 0x3a: //sbc |
| 899 | case 0x3c: //ad |
| 900 | case 0x3e: //sb |
| 901 | { |
| 902 | UINT8 arg = read_op(); |
| 903 | UINT16 offset = REG_IX + get_sign_mreg(arg); |
| 904 | UINT8 src = mem_readbyte(REG_UA>>4, offset); |
| 905 | |
| 906 | UINT16 res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; |
| 907 | |
| 908 | if ((op & 4)) |
| 909 | mem_writebyte(REG_UA>>4, offset, res & 0xff); |
| 910 | |
| 911 | CLEAR_FLAGS; |
| 912 | CHECK_FLAG_Z(res & 0xff); |
| 913 | CHECK_FLAGB_UZ_LZ(res); |
| 914 | CHECK_FLAG_C(res, 0xff); |
| 915 | |
| 916 | m_icount -= 9; |
| 917 | } |
| 918 | break; |
| 919 | |
| 920 | case 0x39: //adc |
| 921 | case 0x3b: //sbc |
| 922 | case 0x3d: //ad |
| 923 | case 0x3f: //sb |
| 924 | { |
| 925 | UINT8 arg = read_op(); |
| 926 | UINT16 offset = REG_IZ + get_sign_mreg(arg); |
| 927 | UINT8 src = mem_readbyte(REG_UA>>6, offset); |
| 928 | |
| 929 | UINT16 res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; |
| 930 | |
| 931 | if ((op & 4)) |
| 932 | mem_writebyte(REG_UA>>6, offset, res & 0xff); |
| 933 | |
| 934 | CLEAR_FLAGS; |
| 935 | CHECK_FLAG_Z(res & 0xff); |
| 936 | CHECK_FLAGB_UZ_LZ(res); |
| 937 | CHECK_FLAG_C(res, 0xff); |
| 938 | |
| 939 | m_icount -= 9; |
| 940 | } |
| 941 | break; |
| 942 | |
| 943 | case 0x40: //adc |
| 944 | case 0x41: //sbc |
| 945 | case 0x48: //ad |
| 946 | case 0x49: //sb |
| 947 | { |
| 948 | UINT8 arg = read_op(); |
| 949 | UINT8 src = read_op(); |
| 950 | UINT16 res = READ_REG(arg) + ((op&1) ? -src : +src); |
| 951 | |
| 952 | COND_WRITE_REG(op, arg, res & 0xff); |
| 953 | |
| 954 | CLEAR_FLAGS; |
| 955 | CHECK_FLAG_Z(res & 0xff); |
| 956 | CHECK_FLAGB_UZ_LZ(res); |
| 957 | CHECK_FLAG_C(res, 0xff); |
| 958 | |
| 959 | check_optional_jr(arg); |
| 960 | m_icount -= 3; |
| 961 | } |
| 962 | break; |
| 963 | |
| 964 | case 0x42: //ld |
| 965 | { |
| 966 | UINT8 arg = read_op(); |
| 967 | UINT8 src = read_op() ; |
| 968 | |
| 969 | WRITE_REG(arg, src); |
| 970 | |
| 971 | check_optional_jr(arg); |
| 972 | m_icount -= 3; |
| 973 | } |
| 974 | break; |
| 975 | |
| 976 | case 0x44: //anc |
| 977 | case 0x45: //nac |
| 978 | case 0x46: //orc |
| 979 | case 0x47: //xrc |
| 980 | case 0x4c: //an |
| 981 | case 0x4d: //na |
| 982 | case 0x4e: //or |
| 983 | case 0x4f: //xr |
| 984 | { |
| 985 | UINT8 arg = read_op(); |
| 986 | UINT8 src = read_op(); |
| 987 | |
| 988 | UINT8 res = make_logic(op, READ_REG(arg), src); |
| 989 | |
| 990 | COND_WRITE_REG(op, arg, res); |
| 991 | |
| 992 | CLEAR_FLAGS; |
| 993 | CHECK_FLAG_Z(res & 0xff); |
| 994 | CHECK_FLAGB_UZ_LZ(res); |
| 995 | |
| 996 | //na(c) and or(c) always set C flag |
| 997 | if ((op&3) == 1 || (op&3) == 2) |
| 998 | SET_FLAG_C; |
| 999 | |
| 1000 | check_optional_jr(arg); |
| 1001 | m_icount -= 3; |
| 1002 | } |
| 1003 | break; |
| 1004 | |
| 1005 | case 0x4a: //adb |
| 1006 | case 0x4b: //sbb |
| 1007 | { |
| 1008 | UINT8 arg = read_op(); |
| 1009 | UINT8 src = read_op(); |
| 1010 | UINT16 res; |
| 1011 | |
| 1012 | if (op & 0x01) |
| 1013 | res = make_bcd_sub(READ_REG(arg), src); |
| 1014 | else |
| 1015 | res = make_bcd_add(READ_REG(arg), src); |
| 1016 | |
| 1017 | WRITE_REG(arg, res & 0xff); |
| 1018 | |
| 1019 | CLEAR_FLAGS; |
| 1020 | CHECK_FLAG_Z(res & 0xff); |
| 1021 | CHECK_FLAGB_UZ_LZ(res); |
| 1022 | CHECK_FLAG_C(res, 0xff); |
| 1023 | |
| 1024 | check_optional_jr(arg); |
| 1025 | m_icount -= 3; |
| 1026 | } |
| 1027 | break; |
| 1028 | |
| 1029 | case 0x50: //st |
| 1030 | { |
| 1031 | UINT8 arg = read_op(); |
| 1032 | UINT8 src = read_op(); |
| 1033 | UINT16 offset = REG_GET16(READ_SREG(arg)); |
| 1034 | |
| 1035 | mem_writebyte(REG_UA>>4, offset, src); |
| 1036 | m_icount -= 8; |
| 1037 | } |
| 1038 | break; |
| 1039 | |
| 1040 | case 0x51: //ld |
| 1041 | { |
| 1042 | UINT8 arg = read_op(); |
| 1043 | UINT8 src = read_op(); |
| 1044 | |
| 1045 | WRITE_REG(arg, src); |
| 1046 | m_icount -= 8; |
| 1047 | } |
| 1048 | break; |
| 1049 | |
| 1050 | case 0x52: //stl |
| 1051 | { |
| 1052 | UINT8 arg = read_op(); |
| 1053 | |
| 1054 | if (m_cpu_config.m_lcd_data_w) |
| 1055 | (*m_cpu_config.m_lcd_data_w)(*this, arg); |
| 1056 | |
| 1057 | m_icount -= 12; |
| 1058 | } |
| 1059 | break; |
| 1060 | |
| 1061 | case 0x54: //ppo/pfl |
| 1062 | { |
| 1063 | UINT8 arg = read_op(); |
| 1064 | UINT8 src = read_op(); |
| 1065 | |
| 1066 | if (arg & 0x40) |
| 1067 | { |
| 1068 | m_flags = (m_flags & 0x0f) | (src & 0xf0); |
| 1069 | } |
| 1070 | else |
| 1071 | { |
| 1072 | if (m_cpu_config.m_lcd_control) |
| 1073 | (*m_cpu_config.m_lcd_control)(*this, src); |
| 1074 | } |
| 1075 | |
| 1076 | m_icount -= 3; |
| 1077 | } |
| 1078 | break; |
| 1079 | |
| 1080 | case 0x55: //psr |
| 1081 | { |
| 1082 | UINT8 arg = read_op(); |
| 1083 | WRITE_SREG(arg, arg&0x1f); |
| 1084 | |
| 1085 | m_icount -= 3; |
| 1086 | } |
| 1087 | break; |
| 1088 | |
| 1089 | case 0x56: //pst |
| 1090 | case 0x57: //pst |
| 1091 | { |
| 1092 | UINT8 arg = read_op(); |
| 1093 | UINT8 src = read_op(); |
| 1094 | UINT8 idx = GET_REG_IDX(op, arg); |
| 1095 | |
| 1096 | switch (idx) |
| 1097 | { |
| 1098 | case 0: //PE |
| 1099 | case 1: //PD |
| 1100 | WRITE_REG8(idx, src); |
| 1101 | if (m_cpu_config.m_port_w) |
| 1102 | (*m_cpu_config.m_port_w)(*this, REG_PD & REG_PE); |
| 1103 | break; |
| 1104 | case 2: //IB |
| 1105 | REG_IB = (REG_IB & 0x1f) | (src & 0xe0); |
| 1106 | break; |
| 1107 | case 3: //UA |
| 1108 | WRITE_REG8(idx, src); |
| 1109 | break; |
| 1110 | case 4: //IA |
| 1111 | if (m_cpu_config.m_kb_w) |
| 1112 | (*m_cpu_config.m_kb_w)(*this, src); |
| 1113 | WRITE_REG8(idx, src); |
| 1114 | break; |
| 1115 | case 5: //IE |
| 1116 | REG_IB &= (((src>>3)&0x1f) | 0xe0); |
| 1117 | m_irq_status &= ((src>>3)&0x1f); |
| 1118 | WRITE_REG8(idx, src); |
| 1119 | break; |
| 1120 | case 6: //TM |
| 1121 | case 7: //TM |
| 1122 | // read-only |
| 1123 | break; |
| 1124 | } |
| 1125 | |
| 1126 | m_icount -= 3; |
| 1127 | } |
| 1128 | break; |
| 1129 | |
| 1130 | case 0x58: //bups |
| 1131 | case 0x59: //bdns |
| 1132 | { |
| 1133 | UINT8 arg = read_op(); |
| 1134 | UINT8 tmp; |
| 1135 | UINT16 res; |
| 1136 | |
| 1137 | do |
| 1138 | { |
| 1139 | tmp = mem_readbyte(REG_UA>>4, REG_IX); |
| 1140 | mem_writebyte(REG_UA>>6, REG_IZ, tmp); |
| 1141 | |
| 1142 | res = tmp - arg; |
| 1143 | if (REG_IX == REG_IY) |
| 1144 | break; |
| 1145 | |
| 1146 | REG_IX += ((op&1) ? -1 : +1); |
| 1147 | REG_IZ += ((op&1) ? -1 : +1); |
| 1148 | m_icount -= 6; |
| 1149 | } while(res); |
| 1150 | |
| 1151 | CLEAR_FLAGS; |
| 1152 | CHECK_FLAG_Z(res & 0xff); |
| 1153 | CHECK_FLAGB_UZ_LZ(res); |
| 1154 | CHECK_FLAG_C(res, 0xff); |
| 1155 | |
| 1156 | m_icount -= 9; |
| 1157 | } |
| 1158 | break; |
| 1159 | |
| 1160 | case 0x5c: //sup |
| 1161 | case 0x5d: //sdn |
| 1162 | { |
| 1163 | UINT8 arg = read_op(); |
| 1164 | UINT16 res; |
| 1165 | |
| 1166 | do |
| 1167 | { |
| 1168 | res = mem_readbyte(REG_UA>>4, REG_IX) - arg; |
| 1169 | |
| 1170 | if (REG_IX == REG_IY) |
| 1171 | break; |
| 1172 | |
| 1173 | REG_IX += ((op&1) ? -1 : +1); |
| 1174 | m_icount -= 6; |
| 1175 | } while(res); |
| 1176 | |
| 1177 | CLEAR_FLAGS; |
| 1178 | CHECK_FLAG_Z(res & 0xff); |
| 1179 | CHECK_FLAGB_UZ_LZ(res); |
| 1180 | CHECK_FLAG_C(res, 0xff); |
| 1181 | |
| 1182 | m_icount -= 9; |
| 1183 | } |
| 1184 | break; |
| 1185 | |
| 1186 | case 0x60: //st |
| 1187 | case 0x62: //sti |
| 1188 | { |
| 1189 | UINT8 arg = read_op(); |
| 1190 | UINT16 prev_ir = REG_IX; |
| 1191 | REG_IX += get_sign_im8(arg); |
| 1192 | |
| 1193 | mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg)); |
| 1194 | |
| 1195 | RESTORE_REG(op, REG_IX, prev_ir); |
| 1196 | |
| 1197 | m_icount -= 8; |
| 1198 | } |
| 1199 | break; |
| 1200 | |
| 1201 | case 0x61: //st |
| 1202 | case 0x63: //sti |
| 1203 | { |
| 1204 | UINT8 arg = read_op(); |
| 1205 | UINT16 prev_ir = REG_IZ; |
| 1206 | REG_IZ += get_sign_im8(arg); |
| 1207 | |
| 1208 | mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg)); |
| 1209 | |
| 1210 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 1211 | m_icount -= 8; |
| 1212 | } |
| 1213 | break; |
| 1214 | |
| 1215 | case 0x64: //std |
| 1216 | { |
| 1217 | UINT8 arg = read_op(); |
| 1218 | REG_IX += get_sign_im8(arg); |
| 1219 | |
| 1220 | mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg)); |
| 1221 | m_icount -= 6; |
| 1222 | } |
| 1223 | break; |
| 1224 | |
| 1225 | case 0x65: //std |
| 1226 | { |
| 1227 | UINT8 arg = read_op(); |
| 1228 | REG_IZ += get_sign_im8(arg); |
| 1229 | |
| 1230 | mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg)); |
| 1231 | m_icount -= 6; |
| 1232 | } |
| 1233 | break; |
| 1234 | |
| 1235 | case 0x68: //ld |
| 1236 | case 0x6a: //ldi |
| 1237 | { |
| 1238 | UINT8 arg = read_op(); |
| 1239 | UINT16 prev_ir = REG_IX; |
| 1240 | REG_IX += get_sign_im8(arg); |
| 1241 | |
| 1242 | WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX++)); |
| 1243 | |
| 1244 | RESTORE_REG(op, REG_IX, prev_ir); |
| 1245 | m_icount -= 8; |
| 1246 | } |
| 1247 | break; |
| 1248 | |
| 1249 | case 0x69: //ld |
| 1250 | case 0x6b: //ldi |
| 1251 | { |
| 1252 | UINT8 arg = read_op(); |
| 1253 | UINT16 prev_ir = REG_IZ; |
| 1254 | REG_IZ += get_sign_im8(arg); |
| 1255 | |
| 1256 | WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ++)); |
| 1257 | |
| 1258 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 1259 | m_icount -= 8; |
| 1260 | } |
| 1261 | break; |
| 1262 | |
| 1263 | case 0x6c: //ldd |
| 1264 | { |
| 1265 | UINT8 arg = read_op(); |
| 1266 | REG_IX += get_sign_im8(arg); |
| 1267 | |
| 1268 | WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX)); |
| 1269 | m_icount -= 6; |
| 1270 | } |
| 1271 | break; |
| 1272 | |
| 1273 | case 0x6d: //ldd |
| 1274 | { |
| 1275 | UINT8 arg = read_op(); |
| 1276 | REG_IZ += get_sign_im8(arg); |
| 1277 | |
| 1278 | WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ)); |
| 1279 | m_icount -= 6; |
| 1280 | } |
| 1281 | break; |
| 1282 | |
| 1283 | case 0x70: //cal z |
| 1284 | case 0x71: //cal nc |
| 1285 | case 0x72: //cal lz |
| 1286 | case 0x73: //cal uz |
| 1287 | case 0x74: //cal nz |
| 1288 | case 0x75: //cal c |
| 1289 | case 0x76: //cal nlz |
| 1290 | case 0x77: //unconditional cal |
| 1291 | { |
| 1292 | UINT8 lsb = read_op(); |
| 1293 | if (m_pc < INT_ROM) read_op(); |
| 1294 | UINT8 msb = read_op(); |
| 1295 | |
| 1296 | if (check_cond(op)) |
| 1297 | { |
| 1298 | m_pc--; |
| 1299 | push(REG_SS, (m_pc>>8)&0xff); |
| 1300 | push(REG_SS, (m_pc>>0)&0xff); |
| 1301 | |
| 1302 | set_pc((msb<<8) | lsb); |
| 1303 | m_icount -= 6; |
| 1304 | } |
| 1305 | m_icount -= 3; |
| 1306 | } |
| 1307 | break; |
| 1308 | |
| 1309 | case 0x78: //adc |
| 1310 | case 0x7a: //sbc |
| 1311 | case 0x7c: //ad |
| 1312 | case 0x7e: //sb |
| 1313 | { |
| 1314 | UINT8 arg = read_op(); |
| 1315 | UINT16 offset = REG_IX + get_sign_im8(arg); |
| 1316 | UINT8 src = mem_readbyte(REG_UA>>4, offset); |
| 1317 | |
| 1318 | UINT16 res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; |
| 1319 | |
| 1320 | if ((op & 4)) |
| 1321 | mem_writebyte(REG_UA>>4, offset, res & 0xff); |
| 1322 | |
| 1323 | CLEAR_FLAGS; |
| 1324 | CHECK_FLAG_Z(res & 0xff); |
| 1325 | CHECK_FLAGB_UZ_LZ(res); |
| 1326 | CHECK_FLAG_C(res, 0xff); |
| 1327 | |
| 1328 | m_icount -= 9; |
| 1329 | } |
| 1330 | break; |
| 1331 | |
| 1332 | case 0x79: //adc |
| 1333 | case 0x7b: //sbc |
| 1334 | case 0x7d: //ad |
| 1335 | case 0x7f: //sb |
| 1336 | { |
| 1337 | UINT8 arg = read_op(); |
| 1338 | UINT16 offset = REG_IZ + get_sign_im8(arg); |
| 1339 | UINT8 src = mem_readbyte(REG_UA>>6, offset); |
| 1340 | |
| 1341 | UINT16 res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; |
| 1342 | |
| 1343 | if ((op & 4)) |
| 1344 | mem_writebyte(REG_UA>>6, offset, res & 0xff); |
| 1345 | |
| 1346 | CLEAR_FLAGS; |
| 1347 | CHECK_FLAG_Z(res & 0xff); |
| 1348 | CHECK_FLAGB_UZ_LZ(res); |
| 1349 | CHECK_FLAG_C(res, 0xff); |
| 1350 | |
| 1351 | m_icount -= 9; |
| 1352 | } |
| 1353 | break; |
| 1354 | |
| 1355 | case 0x80: //adcw |
| 1356 | case 0x81: //sbcw |
| 1357 | case 0x88: //adw |
| 1358 | case 0x89: //sbw |
| 1359 | { |
| 1360 | UINT8 arg = read_op(); |
| 1361 | UINT8 src = get_sir_im8(arg); |
| 1362 | UINT32 res = REG_GET16(arg) + ((op & 0x01) ? -REG_GET16(src) : +REG_GET16(src)); |
| 1363 | |
| 1364 | if (op & 0x08) REG_PUT16(arg, res&0xffff); |
| 1365 | |
| 1366 | CLEAR_FLAGS; |
| 1367 | CHECK_FLAG_Z(res & 0xffff); |
| 1368 | CHECK_FLAGW_UZ_LZ(res); |
| 1369 | CHECK_FLAG_C(res, 0xffff); |
| 1370 | |
| 1371 | check_optional_jr(arg); |
| 1372 | m_icount -= 8; |
| 1373 | } |
| 1374 | break; |
| 1375 | |
| 1376 | case 0x82: //ldw |
| 1377 | { |
| 1378 | UINT8 arg = read_op(); |
| 1379 | UINT8 src = get_sir_im8(arg); |
| 1380 | |
| 1381 | COPY_REG(arg, src); |
| 1382 | COPY_REG(arg+1, src+1); |
| 1383 | |
| 1384 | check_optional_jr(arg); |
| 1385 | m_icount -= 8; |
| 1386 | } |
| 1387 | break; |
| 1388 | |
| 1389 | case 0x84: //ancw |
| 1390 | case 0x85: //nacw |
| 1391 | case 0x86: //orcw |
| 1392 | case 0x87: //xrcw |
| 1393 | case 0x8c: //anw |
| 1394 | case 0x8d: //naw |
| 1395 | case 0x8e: //orw |
| 1396 | case 0x8f: //xrw |
| 1397 | { |
| 1398 | UINT8 arg = read_op(); |
| 1399 | UINT8 src = get_sir_im8(arg); |
| 1400 | |
| 1401 | UINT8 res0 = make_logic(op, READ_REG(arg), READ_REG(src)); |
| 1402 | COND_WRITE_REG(op, arg, res0); |
| 1403 | |
| 1404 | UINT8 res1 = make_logic(op, READ_REG(arg+1), READ_REG(src+1)); |
| 1405 | COND_WRITE_REG(op, arg+1, res1); |
| 1406 | |
| 1407 | CLEAR_FLAGS; |
| 1408 | CHECK_FLAG_Z(res0 || res1); |
| 1409 | CHECK_FLAGB_UZ_LZ(res1); |
| 1410 | |
| 1411 | //na(c) and or(c) always set C flag |
| 1412 | if ((op&3) == 1 || (op&3) == 2) |
| 1413 | SET_FLAG_C; |
| 1414 | |
| 1415 | check_optional_jr(arg); |
| 1416 | m_icount -= 8; |
| 1417 | } |
| 1418 | break; |
| 1419 | |
| 1420 | case 0x8a: //adbw |
| 1421 | case 0x8b: //sbbw |
| 1422 | { |
| 1423 | UINT8 arg = read_op(); |
| 1424 | UINT8 src = get_sir_im8(arg); |
| 1425 | UINT16 res0, res1; |
| 1426 | |
| 1427 | if (op & 0x01) |
| 1428 | res0 = make_bcd_sub(READ_REG(arg), READ_REG(src)); |
| 1429 | else |
| 1430 | res0 = make_bcd_add(READ_REG(arg), READ_REG(src)); |
| 1431 | |
| 1432 | WRITE_REG(arg, res0 & 0xff); |
| 1433 | |
| 1434 | res1 = (res0>0xff) ? 1 : 0 ; |
| 1435 | |
| 1436 | if (op & 0x01) |
| 1437 | res1 = make_bcd_sub(READ_REG(arg+1), READ_REG(src+1) + res1); |
| 1438 | else |
| 1439 | res1 = make_bcd_add(READ_REG(arg+1), READ_REG(src+1) + res1); |
| 1440 | |
| 1441 | WRITE_REG(arg+1, res1 & 0xff); |
| 1442 | |
| 1443 | CLEAR_FLAGS; |
| 1444 | CHECK_FLAG_Z(res0 || res1); |
| 1445 | CHECK_FLAGB_UZ_LZ(res1); |
| 1446 | CHECK_FLAG_C(res1, 0xff); |
| 1447 | |
| 1448 | check_optional_jr(arg); |
| 1449 | m_icount -= 8; |
| 1450 | } |
| 1451 | break; |
| 1452 | |
| 1453 | case 0x90: //stw |
| 1454 | { |
| 1455 | UINT8 arg = read_op(); |
| 1456 | UINT8 src = get_sir_im8(arg); |
| 1457 | UINT16 offset = REG_GET16(src); |
| 1458 | |
| 1459 | mem_writebyte(REG_UA>>4, offset+0, READ_REG(arg+0)); |
| 1460 | mem_writebyte(REG_UA>>4, offset+1, READ_REG(arg+1)); |
| 1461 | |
| 1462 | check_optional_jr(arg); |
| 1463 | m_icount -= 11; |
| 1464 | } |
| 1465 | break; |
| 1466 | |
| 1467 | case 0x91: //ldw |
| 1468 | { |
| 1469 | UINT8 arg = read_op(); |
| 1470 | UINT8 src = get_sir_im8(arg); |
| 1471 | UINT16 offset = REG_GET16(src); |
| 1472 | |
| 1473 | WRITE_REG(arg+0, mem_readbyte(REG_UA>>4, offset+0)); |
| 1474 | WRITE_REG(arg+1, mem_readbyte(REG_UA>>4, offset+1)); |
| 1475 | |
| 1476 | check_optional_jr(arg); |
| 1477 | m_icount -= 11; |
| 1478 | } |
| 1479 | break; |
| 1480 | |
| 1481 | case 0x92: //stlw |
| 1482 | { |
| 1483 | UINT8 arg = read_op(); |
| 1484 | |
| 1485 | if (m_cpu_config.m_lcd_data_w) |
| 1486 | { |
| 1487 | (*m_cpu_config.m_lcd_data_w)(*this, READ_REG(arg)); |
| 1488 | (*m_cpu_config.m_lcd_data_w)(*this, READ_REG(arg+1)); |
| 1489 | } |
| 1490 | |
| 1491 | check_optional_jr(arg); |
| 1492 | m_icount -= 19; |
| 1493 | } |
| 1494 | break; |
| 1495 | |
| 1496 | case 0x93: //ldcw |
| 1497 | { |
| 1498 | UINT8 arg = read_op(); |
| 1499 | UINT8 reg0, reg1; |
| 1500 | |
| 1501 | if (m_cpu_config.m_lcd_data_r) |
| 1502 | { |
| 1503 | reg0 = (*m_cpu_config.m_lcd_data_r)(*this); |
| 1504 | reg1 = (*m_cpu_config.m_lcd_data_r)(*this); |
| 1505 | } |
| 1506 | else |
| 1507 | reg0 = reg1 = 0xff; |
| 1508 | |
| 1509 | WRITE_REG(arg+0, reg0); |
| 1510 | WRITE_REG(arg+1, reg1); |
| 1511 | |
| 1512 | check_optional_jr(arg); |
| 1513 | m_icount -= 19; |
| 1514 | } |
| 1515 | break; |
| 1516 | |
| 1517 | case 0x96: //pre |
| 1518 | case 0x97: //pre |
| 1519 | { |
| 1520 | UINT8 arg = read_op(); |
| 1521 | UINT8 idx = GET_REG_IDX(op, arg); |
| 1522 | |
| 1523 | if (idx < 5) |
| 1524 | m_reg16bit[idx] = REG_GET16(arg); |
| 1525 | |
| 1526 | check_optional_jr(arg); |
| 1527 | m_icount -= 8; |
| 1528 | } |
| 1529 | break; |
| 1530 | |
| 1531 | case 0x98: //rodw |
| 1532 | { |
| 1533 | UINT8 arg = read_op(); |
| 1534 | UINT8 op1 = (arg>>5) & 0x03; |
| 1535 | switch (op1) |
| 1536 | { |
| 1537 | case 0x00: //rodw |
| 1538 | case 0x02: //bidw |
| 1539 | { |
| 1540 | UINT16 src = REG_GET16(arg-1); |
| 1541 | UINT16 res = (src>>1)&0x7fff; |
| 1542 | |
| 1543 | if (!(op1&0x02)) |
| 1544 | res = res | ((m_flags&FLAG_C) !=0 )<<15; |
| 1545 | |
| 1546 | REG_PUT16(arg-1, res); |
| 1547 | |
| 1548 | CLEAR_FLAGS; |
| 1549 | CHECK_FLAG_Z(res & 0xffff); |
| 1550 | CHECK_FLAGB_UZ_LZ(res); |
| 1551 | if (src&0x01) SET_FLAG_C; |
| 1552 | } |
| 1553 | break; |
| 1554 | |
| 1555 | case 0x01: //rouw |
| 1556 | case 0x03: //biuw |
| 1557 | { |
| 1558 | UINT16 src = REG_GET16(arg); |
| 1559 | UINT16 res = (src<<1)&0xfffe; |
| 1560 | |
| 1561 | if (!(op1&0x02)) |
| 1562 | res = res | ((m_flags&FLAG_C) !=0 )<<0; |
| 1563 | |
| 1564 | REG_PUT16(arg, res); |
| 1565 | |
| 1566 | CLEAR_FLAGS; |
| 1567 | CHECK_FLAG_Z(res & 0xffff); |
| 1568 | CHECK_FLAGW_UZ_LZ(res); |
| 1569 | if (src&0x8000) SET_FLAG_C; |
| 1570 | } |
| 1571 | break; |
| 1572 | } |
| 1573 | |
| 1574 | check_optional_jr(arg); |
| 1575 | m_icount -= 11; |
| 1576 | } |
| 1577 | break; |
| 1578 | |
| 1579 | case 0x9a: |
| 1580 | { |
| 1581 | UINT8 arg = read_op(); |
| 1582 | UINT8 op1 = (arg>>5) & 0x03; |
| 1583 | switch (op1) |
| 1584 | { |
| 1585 | case 0x00: //didw |
| 1586 | { |
| 1587 | UINT16 src = (REG_GET16(arg-1)>>4)&0x0fff; |
| 1588 | REG_PUT16(arg-1, src); |
| 1589 | |
| 1590 | CLEAR_FLAGS; |
| 1591 | CHECK_FLAG_Z(src & 0xffff); |
| 1592 | CHECK_FLAGB_UZ_LZ(src); |
| 1593 | } |
| 1594 | break; |
| 1595 | |
| 1596 | case 0x01: //diuw |
| 1597 | { |
| 1598 | UINT16 src = (REG_GET16(arg)<<4)&0xfff0; |
| 1599 | REG_PUT16(arg, src); |
| 1600 | |
| 1601 | CLEAR_FLAGS; |
| 1602 | CHECK_FLAG_Z(src & 0xffff); |
| 1603 | CHECK_FLAGW_UZ_LZ(src); |
| 1604 | } |
| 1605 | break; |
| 1606 | |
| 1607 | case 0x02: //bydw |
| 1608 | { |
| 1609 | UINT8 src = READ_REG(arg); |
| 1610 | |
| 1611 | WRITE_REG(arg, 0); |
| 1612 | WRITE_REG(arg-1, src); |
| 1613 | |
| 1614 | CLEAR_FLAGS; |
| 1615 | CHECK_FLAG_Z(src & 0xff); |
| 1616 | CHECK_FLAGB_UZ_LZ(src); |
| 1617 | } |
| 1618 | break; |
| 1619 | |
| 1620 | case 0x03: //byuw |
| 1621 | { |
| 1622 | UINT8 src = READ_REG(arg); |
| 1623 | |
| 1624 | WRITE_REG(arg, 0); |
| 1625 | WRITE_REG(arg+1, src); |
| 1626 | |
| 1627 | CLEAR_FLAGS; |
| 1628 | CHECK_FLAG_Z(src & 0xff); |
| 1629 | CHECK_FLAGB_UZ_LZ(src); |
| 1630 | } |
| 1631 | break; |
| 1632 | } |
| 1633 | |
| 1634 | check_optional_jr(arg); |
| 1635 | m_icount -= 11; |
| 1636 | } |
| 1637 | break; |
| 1638 | |
| 1639 | case 0x9b: //cmpw/invw |
| 1640 | { |
| 1641 | UINT8 arg = read_op(); |
| 1642 | UINT16 res = ~(REG_GET16(arg)); |
| 1643 | if (!(arg & 0x40)) res++; |
| 1644 | |
| 1645 | REG_PUT16(arg, res); |
| 1646 | |
| 1647 | CLEAR_FLAGS; |
| 1648 | CHECK_FLAG_Z(res & 0xffff); |
| 1649 | CHECK_FLAGW_UZ_LZ(res); |
| 1650 | |
| 1651 | if (res || (arg & 0x40)) SET_FLAG_C; |
| 1652 | |
| 1653 | check_optional_jr(arg); |
| 1654 | m_icount -= 8; |
| 1655 | } |
| 1656 | break; |
| 1657 | |
| 1658 | case 0x9c: //gpow/gflw |
| 1659 | { |
| 1660 | UINT8 arg = read_op(); |
| 1661 | UINT8 reg0, reg1; |
| 1662 | |
| 1663 | if (arg&0x40) |
| 1664 | { |
| 1665 | reg0 = reg1 = m_flags; |
| 1666 | } |
| 1667 | else |
| 1668 | { |
| 1669 | if (m_cpu_config.m_port_r) |
| 1670 | { |
| 1671 | reg0 = (*m_cpu_config.m_port_r)(*this); |
| 1672 | reg1 = (*m_cpu_config.m_port_r)(*this); |
| 1673 | } |
| 1674 | else |
| 1675 | reg0 = reg1 = 0xff; |
| 1676 | |
| 1677 | reg0&=(~REG_PE); |
| 1678 | reg1&=(~REG_PE); |
| 1679 | |
| 1680 | } |
| 1681 | |
| 1682 | WRITE_REG(arg+0, reg0); |
| 1683 | WRITE_REG(arg+1, reg1); |
| 1684 | |
| 1685 | check_optional_jr(arg); |
| 1686 | m_icount -= 8; |
| 1687 | } |
| 1688 | break; |
| 1689 | |
| 1690 | case 0x9e: //gre |
| 1691 | case 0x9f: //gre |
| 1692 | { |
| 1693 | UINT8 arg = read_op(); |
| 1694 | UINT8 idx = GET_REG_IDX(op, arg); |
| 1695 | UINT16 src; |
| 1696 | |
| 1697 | if (idx >= 5) |
| 1698 | { |
| 1699 | UINT16 port = 0xff; |
| 1700 | |
| 1701 | if (m_cpu_config.m_kb_r) |
| 1702 | port = (*m_cpu_config.m_kb_r)(*this); |
| 1703 | |
| 1704 | src = (REG_KY & 0x0f00) | (port & 0xf0ff); |
| 1705 | } |
| 1706 | else |
| 1707 | src = m_reg16bit[idx]; |
| 1708 | |
| 1709 | REG_PUT16(arg, src); |
| 1710 | |
| 1711 | check_optional_jr(arg); |
| 1712 | m_icount -= 8; |
| 1713 | } |
| 1714 | break; |
| 1715 | |
| 1716 | case 0xa0: //stw |
| 1717 | case 0xa2: //stiw |
| 1718 | { |
| 1719 | UINT8 arg = read_op(); |
| 1720 | UINT16 prev_ir = REG_IX; |
| 1721 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1722 | |
| 1723 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1724 | |
| 1725 | mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg+0)); |
| 1726 | mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg+1)); |
| 1727 | |
| 1728 | RESTORE_REG(op, REG_IX, prev_ir); |
| 1729 | m_icount -= 11; |
| 1730 | } |
| 1731 | break; |
| 1732 | |
| 1733 | case 0xa1: //stw |
| 1734 | case 0xa3: //stiw |
| 1735 | { |
| 1736 | UINT8 arg = read_op(); |
| 1737 | UINT16 prev_ir = REG_IZ; |
| 1738 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1739 | |
| 1740 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1741 | |
| 1742 | mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg+0)); |
| 1743 | mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg+1)); |
| 1744 | |
| 1745 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 1746 | m_icount -= 11; |
| 1747 | } |
| 1748 | break; |
| 1749 | |
| 1750 | case 0xa4: //stdw |
| 1751 | { |
| 1752 | UINT8 arg = read_op(); |
| 1753 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1754 | |
| 1755 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1756 | |
| 1757 | mem_writebyte(REG_UA>>4, REG_IX--, READ_REG(arg-0)); |
| 1758 | mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg-1)); |
| 1759 | |
| 1760 | m_icount -= 9; |
| 1761 | } |
| 1762 | break; |
| 1763 | case 0xa5: //stdw |
| 1764 | { |
| 1765 | UINT8 arg = read_op(); |
| 1766 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1767 | |
| 1768 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1769 | |
| 1770 | mem_writebyte(REG_UA>>6, REG_IZ--, READ_REG(arg-0)); |
| 1771 | mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg-1)); |
| 1772 | |
| 1773 | m_icount -= 9; |
| 1774 | } |
| 1775 | break; |
| 1776 | |
| 1777 | case 0xa6: //phsw |
| 1778 | { |
| 1779 | UINT8 arg = read_op(); |
| 1780 | push(REG_SS, READ_REG(arg)); |
| 1781 | push(REG_SS, READ_REG(arg-1)); |
| 1782 | |
| 1783 | m_icount -= 12; |
| 1784 | } |
| 1785 | break; |
| 1786 | case 0xa7: //phuw |
| 1787 | { |
| 1788 | UINT8 arg = read_op(); |
| 1789 | push(REG_US, READ_REG(arg)); |
| 1790 | push(REG_US, READ_REG(arg-1)); |
| 1791 | |
| 1792 | m_icount -= 12; |
| 1793 | } |
| 1794 | break; |
| 1795 | |
| 1796 | case 0xa8: //ldw |
| 1797 | case 0xaa: //ldiw |
| 1798 | { |
| 1799 | UINT8 arg = read_op(); |
| 1800 | UINT16 prev_ir = REG_IX; |
| 1801 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1802 | |
| 1803 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1804 | |
| 1805 | WRITE_REG(arg+0, mem_readbyte(REG_UA>>4, REG_IX++)); |
| 1806 | WRITE_REG(arg+1, mem_readbyte(REG_UA>>4, REG_IX++)); |
| 1807 | |
| 1808 | RESTORE_REG(op, REG_IX, prev_ir); |
| 1809 | |
| 1810 | m_icount -= 11; |
| 1811 | } |
| 1812 | break; |
| 1813 | |
| 1814 | case 0xa9: //ldw |
| 1815 | case 0xab: //ldiw |
| 1816 | { |
| 1817 | UINT8 arg = read_op(); |
| 1818 | UINT16 prev_ir = REG_IZ; |
| 1819 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1820 | |
| 1821 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1822 | |
| 1823 | WRITE_REG(arg+0, mem_readbyte(REG_UA>>6, REG_IZ++)); |
| 1824 | WRITE_REG(arg+1, mem_readbyte(REG_UA>>6, REG_IZ++)); |
| 1825 | |
| 1826 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 1827 | |
| 1828 | m_icount -= 11; |
| 1829 | } |
| 1830 | break; |
| 1831 | |
| 1832 | case 0xac: //lddw |
| 1833 | { |
| 1834 | UINT8 arg = read_op(); |
| 1835 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1836 | |
| 1837 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1838 | |
| 1839 | WRITE_REG(arg-0, mem_readbyte(REG_UA>>4, REG_IX--)); |
| 1840 | WRITE_REG(arg-1, mem_readbyte(REG_UA>>4, REG_IX)); |
| 1841 | |
| 1842 | m_icount -= 9; |
| 1843 | } |
| 1844 | break; |
| 1845 | |
| 1846 | case 0xad: //lddw |
| 1847 | { |
| 1848 | UINT8 arg = read_op(); |
| 1849 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1850 | |
| 1851 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1852 | |
| 1853 | WRITE_REG(arg-0, mem_readbyte(REG_UA>>6, REG_IZ--)); |
| 1854 | WRITE_REG(arg-1, mem_readbyte(REG_UA>>6, REG_IZ)); |
| 1855 | |
| 1856 | m_icount -= 9; |
| 1857 | } |
| 1858 | break; |
| 1859 | |
| 1860 | case 0xae: //ppsw |
| 1861 | case 0xaf: //ppuw |
| 1862 | { |
| 1863 | UINT8 arg = read_op(); |
| 1864 | |
| 1865 | WRITE_REG(arg, pop((op&1) ? REG_US : REG_SS)); |
| 1866 | WRITE_REG(arg+1, pop((op&1) ? REG_US : REG_SS)); |
| 1867 | |
| 1868 | m_icount -= 14; |
| 1869 | } |
| 1870 | break; |
| 1871 | |
| 1872 | case 0xb0: //jr z |
| 1873 | case 0xb1: //jr nc |
| 1874 | case 0xb2: //jr lz |
| 1875 | case 0xb3: //jr uz |
| 1876 | case 0xb4: //jr nz |
| 1877 | case 0xb5: //jr c |
| 1878 | case 0xb6: //jr nlz |
| 1879 | case 0xb7: //unconditional jr |
| 1880 | { |
| 1881 | UINT8 arg = read_op(); |
| 1882 | UINT32 new_pc = m_pc-1 + get_im_7(arg); |
| 1883 | |
| 1884 | if (check_cond(op)) |
| 1885 | set_pc(new_pc); |
| 1886 | m_icount -= 3; |
| 1887 | } |
| 1888 | break; |
| 1889 | |
| 1890 | case 0xb8: //adcw |
| 1891 | case 0xbc: //adw |
| 1892 | { |
| 1893 | UINT8 arg = read_op(); |
| 1894 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1895 | |
| 1896 | UINT16 offset = REG_IX + ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1897 | |
| 1898 | UINT16 src0 = mem_readbyte(REG_UA>>4, offset) + READ_REG(arg); |
| 1899 | UINT16 src1 = mem_readbyte(REG_UA>>4, offset+1) + READ_REG(arg+1) + ((src0>0xff) ? 1 : 0); |
| 1900 | |
| 1901 | if (op&0x04) |
| 1902 | { |
| 1903 | mem_writebyte(REG_UA>>4, offset+0, src0 & 0xff); |
| 1904 | mem_writebyte(REG_UA>>4, offset+1, src1 & 0xff); |
| 1905 | } |
| 1906 | |
| 1907 | CLEAR_FLAGS; |
| 1908 | CHECK_FLAGB_UZ_LZ(src1); |
| 1909 | CHECK_FLAG_Z(src0 || src1); |
| 1910 | CHECK_FLAG_C(src1, 0xff); |
| 1911 | |
| 1912 | m_icount -= 15; |
| 1913 | } |
| 1914 | break; |
| 1915 | |
| 1916 | case 0xba: //sbcw |
| 1917 | case 0xbe: //sbw |
| 1918 | { |
| 1919 | UINT8 arg = read_op(); |
| 1920 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1921 | |
| 1922 | UINT16 offset = REG_IX + ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1923 | |
| 1924 | UINT16 src0 = mem_readbyte(REG_UA>>4, offset) - READ_REG(arg); |
| 1925 | UINT16 src1 = mem_readbyte(REG_UA>>4, offset+1) - READ_REG(arg+1) - ((src0>0xff) ? 1 : 0); |
| 1926 | |
| 1927 | if (op&0x04) |
| 1928 | { |
| 1929 | mem_writebyte(REG_UA>>4, offset+0, src0 & 0xff); |
| 1930 | mem_writebyte(REG_UA>>4, offset+1, src1 & 0xff); |
| 1931 | } |
| 1932 | |
| 1933 | CLEAR_FLAGS; |
| 1934 | CHECK_FLAGB_UZ_LZ(src1); |
| 1935 | CHECK_FLAG_Z(src0 || src1); |
| 1936 | CHECK_FLAG_C(src1, 0xff); |
| 1937 | |
| 1938 | m_icount -= 15; |
| 1939 | } |
| 1940 | break; |
| 1941 | |
| 1942 | case 0xb9: //adcw |
| 1943 | case 0xbd: //adw |
| 1944 | { |
| 1945 | UINT8 arg = read_op(); |
| 1946 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1947 | |
| 1948 | UINT16 offset = REG_IZ + ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1949 | |
| 1950 | UINT16 src0 = mem_readbyte(REG_UA>>6, offset) + READ_REG(arg); |
| 1951 | UINT16 src1 = mem_readbyte(REG_UA>>6, offset+1) + READ_REG(arg+1) + ((src0>0xff) ? 1 : 0); |
| 1952 | |
| 1953 | if (op&0x04) |
| 1954 | { |
| 1955 | mem_writebyte(REG_UA>>6, offset+0, src0 & 0xff); |
| 1956 | mem_writebyte(REG_UA>>6, offset+1, src1 & 0xff); |
| 1957 | } |
| 1958 | |
| 1959 | CLEAR_FLAGS; |
| 1960 | CHECK_FLAGB_UZ_LZ(src1); |
| 1961 | CHECK_FLAG_Z(src0 || src1); |
| 1962 | CHECK_FLAG_C(src1, 0xff); |
| 1963 | |
| 1964 | m_icount -= 15; |
| 1965 | } |
| 1966 | break; |
| 1967 | |
| 1968 | case 0xbb: //sbcw |
| 1969 | case 0xbf: //sbw |
| 1970 | { |
| 1971 | UINT8 arg = read_op(); |
| 1972 | UINT8 ir_inc = READ_REG(get_sir_im8(arg)); |
| 1973 | |
| 1974 | UINT16 offset = REG_IZ + ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 1975 | |
| 1976 | UINT16 src0 = mem_readbyte(REG_UA>>6, offset) - READ_REG(arg); |
| 1977 | UINT16 src1 = mem_readbyte(REG_UA>>6, offset+1) - READ_REG(arg+1) - ((src0>0xff) ? 1 : 0); |
| 1978 | |
| 1979 | if (op&0x04) |
| 1980 | { |
| 1981 | mem_writebyte(REG_UA>>6, offset+0, src0 & 0xff); |
| 1982 | mem_writebyte(REG_UA>>6, offset+1, src1 & 0xff); |
| 1983 | } |
| 1984 | |
| 1985 | CLEAR_FLAGS; |
| 1986 | CHECK_FLAGB_UZ_LZ(src1); |
| 1987 | CHECK_FLAG_Z(src0 || src1); |
| 1988 | CHECK_FLAG_C(src1, 0xff); |
| 1989 | |
| 1990 | m_icount -= 15; |
| 1991 | } |
| 1992 | break; |
| 1993 | |
| 1994 | case 0xc0: //adbcm |
| 1995 | case 0xc1: //sbbcm |
| 1996 | case 0xc8: //adbm |
| 1997 | case 0xc9: //sbbm |
| 1998 | { |
| 1999 | UINT8 arg = read_op(); |
| 2000 | UINT8 arg1 = read_op(); |
| 2001 | UINT8 dst = arg; |
| 2002 | UINT8 src = get_sir_im8(arg, arg1); |
| 2003 | UINT8 c, f; |
| 2004 | UINT16 res = 0; |
| 2005 | |
| 2006 | c = f = 0; |
| 2007 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2008 | { |
| 2009 | if (op & 0x01) |
| 2010 | res = make_bcd_sub(READ_REG(dst), READ_REG(src) + c); |
| 2011 | else |
| 2012 | res = make_bcd_add(READ_REG(dst), READ_REG(src) + c); |
| 2013 | |
| 2014 | c = (res > 0xff) ? 1 : 0; |
| 2015 | |
| 2016 | COND_WRITE_REG(op, dst, res&0xff); |
| 2017 | |
| 2018 | f |= (res&0xff); |
| 2019 | dst++; src++; |
| 2020 | |
| 2021 | m_icount -= 5; |
| 2022 | } |
| 2023 | |
| 2024 | CLEAR_FLAGS; |
| 2025 | CHECK_FLAG_Z(f); |
| 2026 | CHECK_FLAGB_UZ_LZ(res); |
| 2027 | CHECK_FLAG_C(res, 0xff); |
| 2028 | |
| 2029 | check_optional_jr(arg); |
| 2030 | m_icount -= 2; |
| 2031 | } |
| 2032 | break; |
| 2033 | |
| 2034 | case 0xc2: //ldm |
| 2035 | { |
| 2036 | UINT8 arg = read_op(); |
| 2037 | UINT8 arg1 = read_op(); |
| 2038 | UINT8 dst = arg; |
| 2039 | UINT8 src = get_sir_im8(arg, arg1); |
| 2040 | |
| 2041 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2042 | { |
| 2043 | COPY_REG(dst++, src++); |
| 2044 | m_icount -= 5; |
| 2045 | } |
| 2046 | |
| 2047 | check_optional_jr(arg); |
| 2048 | m_icount -= 2; |
| 2049 | } |
| 2050 | break; |
| 2051 | |
| 2052 | case 0xc4: //ancm |
| 2053 | case 0xc5: //nacm |
| 2054 | case 0xc6: //orcm |
| 2055 | case 0xc7: //xrcm |
| 2056 | case 0xcc: //anm |
| 2057 | case 0xcd: //nam |
| 2058 | case 0xce: //orm |
| 2059 | case 0xcf: //xrm |
| 2060 | { |
| 2061 | UINT8 arg = read_op(); |
| 2062 | UINT8 arg1 = read_op(); |
| 2063 | UINT8 dst = arg; |
| 2064 | UINT8 src = get_sir_im8(arg, arg1); |
| 2065 | UINT8 res = 0, f = 0; |
| 2066 | |
| 2067 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2068 | { |
| 2069 | res = make_logic(op, READ_REG(dst), READ_REG(src)); |
| 2070 | |
| 2071 | COND_WRITE_REG(op, dst, res); |
| 2072 | |
| 2073 | f |= res; |
| 2074 | |
| 2075 | dst++; src++; |
| 2076 | |
| 2077 | m_icount -= 3; |
| 2078 | } |
| 2079 | |
| 2080 | CLEAR_FLAGS; |
| 2081 | CHECK_FLAG_Z(f); |
| 2082 | CHECK_FLAGB_UZ_LZ(res); |
| 2083 | |
| 2084 | //na(c) and or(c) always set C flag |
| 2085 | if ((op&3) == 1 || (op&3) == 2) |
| 2086 | SET_FLAG_C; |
| 2087 | |
| 2088 | check_optional_jr(arg); |
| 2089 | } |
| 2090 | break; |
| 2091 | |
| 2092 | case 0xca: //adbm |
| 2093 | case 0xcb: //sbbm |
| 2094 | { |
| 2095 | UINT8 arg = read_op(); |
| 2096 | UINT8 arg1 = read_op(); |
| 2097 | UINT8 dst = arg; |
| 2098 | UINT16 res = 0; |
| 2099 | UINT8 src, f; |
| 2100 | src = arg1 & 0x1f; |
| 2101 | f = 0; |
| 2102 | |
| 2103 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2104 | { |
| 2105 | if (op & 0x01) |
| 2106 | res = make_bcd_sub(READ_REG(dst), src); |
| 2107 | else |
| 2108 | res = make_bcd_add(READ_REG(dst), src); |
| 2109 | |
| 2110 | src = (res > 0xff) ? 1 : 0; |
| 2111 | |
| 2112 | COND_WRITE_REG(op, dst, res&0xff); |
| 2113 | |
| 2114 | f |= (res&0xff); |
| 2115 | dst++; |
| 2116 | |
| 2117 | m_icount -= 5; |
| 2118 | } |
| 2119 | |
| 2120 | CLEAR_FLAGS; |
| 2121 | CHECK_FLAG_Z(f); |
| 2122 | CHECK_FLAGB_UZ_LZ(res); |
| 2123 | CHECK_FLAG_C(res, 0xff); |
| 2124 | |
| 2125 | check_optional_jr(arg); |
| 2126 | m_icount -= 2; |
| 2127 | } |
| 2128 | break; |
| 2129 | |
| 2130 | case 0xd0: //stw |
| 2131 | { |
| 2132 | UINT8 arg = read_op(); |
| 2133 | UINT16 offset = REG_GET16(READ_SREG(arg)); |
| 2134 | |
| 2135 | mem_writebyte(REG_UA>>4, offset+0, read_op()); |
| 2136 | mem_writebyte(REG_UA>>4, offset+1, read_op()); |
| 2137 | |
| 2138 | m_icount -= 11; |
| 2139 | } |
| 2140 | break; |
| 2141 | |
| 2142 | case 0xd1: //ldw |
| 2143 | { |
| 2144 | UINT8 arg = read_op(); |
| 2145 | UINT8 reg0 = read_op(); |
| 2146 | UINT8 reg1 = read_op(); |
| 2147 | |
| 2148 | WRITE_REG(arg+0, reg0); |
| 2149 | WRITE_REG(arg+1, reg1); |
| 2150 | m_icount -= 11; |
| 2151 | } |
| 2152 | break; |
| 2153 | |
| 2154 | case 0xd2: //stlm |
| 2155 | { |
| 2156 | UINT8 arg = read_op(); |
| 2157 | UINT8 arg1 = read_op(); |
| 2158 | |
| 2159 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2160 | { |
| 2161 | if (m_cpu_config.m_lcd_data_w) |
| 2162 | (*m_cpu_config.m_lcd_data_w)(*this, READ_REG(arg)); |
| 2163 | |
| 2164 | arg++; |
| 2165 | m_icount -= 8; |
| 2166 | } |
| 2167 | |
| 2168 | m_icount -= 3; |
| 2169 | } |
| 2170 | break; |
| 2171 | |
| 2172 | case 0xd3: //ldlm |
| 2173 | { |
| 2174 | UINT8 arg = read_op(); |
| 2175 | UINT8 arg1 = read_op(); |
| 2176 | UINT8 src; |
| 2177 | |
| 2178 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2179 | { |
| 2180 | if (m_cpu_config.m_lcd_data_r) |
| 2181 | src = (*m_cpu_config.m_lcd_data_r)(*this); |
| 2182 | else |
| 2183 | src = 0xff; |
| 2184 | |
| 2185 | WRITE_REG(arg, src++); |
| 2186 | |
| 2187 | m_icount -= 8; |
| 2188 | } |
| 2189 | |
| 2190 | m_icount -= 3; |
| 2191 | } |
| 2192 | break; |
| 2193 | |
| 2194 | case 0xd6: //pre |
| 2195 | case 0xd7: //pre |
| 2196 | { |
| 2197 | UINT8 arg = read_op(); |
| 2198 | UINT8 lsb = read_op(); |
| 2199 | UINT8 msb = read_op(); |
| 2200 | UINT8 idx = GET_REG_IDX(op, arg); |
| 2201 | |
| 2202 | if (idx < 5) |
| 2203 | m_reg16bit[idx] = (msb<<8) | lsb; |
| 2204 | |
| 2205 | m_icount -= 8; |
| 2206 | } |
| 2207 | break; |
| 2208 | |
| 2209 | case 0xd8: //bup |
| 2210 | case 0xd9: //bdn |
| 2211 | { |
| 2212 | UINT8 src; |
| 2213 | for(;;) |
| 2214 | { |
| 2215 | src = mem_readbyte(REG_UA>>4, REG_IX); |
| 2216 | mem_writebyte(REG_UA>>6, REG_IZ, src); |
| 2217 | |
| 2218 | if (REG_IX == REG_IY) |
| 2219 | break; |
| 2220 | |
| 2221 | REG_IX += ((op&1) ? -1 : +1); |
| 2222 | REG_IZ += ((op&1) ? -1 : +1); |
| 2223 | m_icount -= 6; |
| 2224 | } |
| 2225 | |
| 2226 | m_icount -= 9; |
| 2227 | } |
| 2228 | break; |
| 2229 | |
| 2230 | case 0xda: |
| 2231 | { |
| 2232 | UINT8 arg = read_op(); |
| 2233 | UINT8 op1 = (arg>>5) & 0x03; |
| 2234 | switch (op1) |
| 2235 | { |
| 2236 | case 0x00: //didm |
| 2237 | { |
| 2238 | UINT8 arg1 = read_op(); |
| 2239 | UINT8 r1 = 0, r2 = 0; |
| 2240 | |
| 2241 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2242 | { |
| 2243 | r2 = r1; |
| 2244 | r1 = READ_REG(arg); |
| 2245 | r2 = ((r1>>4)&0x0f) | ((r2<<4)&0xf0); |
| 2246 | WRITE_REG(arg--, r2); |
| 2247 | m_icount -= 5; |
| 2248 | } |
| 2249 | |
| 2250 | CLEAR_FLAGS; |
| 2251 | CHECK_FLAGB_UZ_LZ(r2); |
| 2252 | CHECK_FLAG_Z(r2); |
| 2253 | } |
| 2254 | break; |
| 2255 | |
| 2256 | case 0x01: //dium |
| 2257 | { |
| 2258 | UINT8 arg1 = read_op(); |
| 2259 | UINT8 r1 = 0, r2 = 0; |
| 2260 | |
| 2261 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2262 | { |
| 2263 | r2 = r1; |
| 2264 | r1 = READ_REG(arg); |
| 2265 | r2 = ((r1<<4)&0xf0) | ((r2>>4)&0x0f); |
| 2266 | WRITE_REG(arg++, r2); |
| 2267 | m_icount -= 5; |
| 2268 | } |
| 2269 | |
| 2270 | CLEAR_FLAGS; |
| 2271 | CHECK_FLAGB_UZ_LZ(r2); |
| 2272 | CHECK_FLAG_Z(r2); |
| 2273 | } |
| 2274 | break; |
| 2275 | |
| 2276 | case 0x02: //bydm |
| 2277 | { |
| 2278 | UINT8 arg1 = read_op(); |
| 2279 | UINT8 r1 = 0, r2 = 0, f = 0; |
| 2280 | |
| 2281 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2282 | { |
| 2283 | r2 = r1; |
| 2284 | r1 = READ_REG(arg); |
| 2285 | WRITE_REG(arg--, r2); |
| 2286 | f |= r2; |
| 2287 | m_icount -= 5; |
| 2288 | } |
| 2289 | |
| 2290 | CLEAR_FLAGS; |
| 2291 | CHECK_FLAGB_UZ_LZ(r2); |
| 2292 | CHECK_FLAG_Z(f); |
| 2293 | } |
| 2294 | break; |
| 2295 | |
| 2296 | case 0x03: //byum |
| 2297 | { |
| 2298 | UINT8 arg1 = read_op(); |
| 2299 | UINT8 r1 = 0, r2 = 0, f = 0; |
| 2300 | |
| 2301 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2302 | { |
| 2303 | r2 = r1; |
| 2304 | r1 = READ_REG(arg); |
| 2305 | WRITE_REG(arg++, r2); |
| 2306 | f |= r2; |
| 2307 | m_icount -= 5; |
| 2308 | } |
| 2309 | |
| 2310 | CLEAR_FLAGS; |
| 2311 | CHECK_FLAGB_UZ_LZ(r2); |
| 2312 | CHECK_FLAG_Z(f); |
| 2313 | } |
| 2314 | break; |
| 2315 | } |
| 2316 | } |
| 2317 | break; |
| 2318 | |
| 2319 | case 0xdb: //cmpm/invm |
| 2320 | { |
| 2321 | UINT8 arg = read_op(); |
| 2322 | UINT8 arg1 = read_op(); |
| 2323 | UINT8 r1 = 0, r2 = 0, f = 0; |
| 2324 | |
| 2325 | r2 = (arg&0x40) ? 0 : 1; |
| 2326 | |
| 2327 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2328 | { |
| 2329 | r1 = r2 + (~READ_REG(arg)); |
| 2330 | WRITE_REG(arg++, r1); |
| 2331 | if (r1) r2 = 0; |
| 2332 | |
| 2333 | f |= r1; |
| 2334 | |
| 2335 | m_icount -= 5; |
| 2336 | } |
| 2337 | |
| 2338 | CLEAR_FLAGS; |
| 2339 | CHECK_FLAG_Z(f); |
| 2340 | CHECK_FLAGB_UZ_LZ(r1); |
| 2341 | if (f != 0 || (arg & 0x40)) |
| 2342 | SET_FLAG_C; |
| 2343 | } |
| 2344 | break; |
| 2345 | |
| 2346 | case 0xdc: //sup |
| 2347 | case 0xdd: //sdn |
| 2348 | { |
| 2349 | UINT8 arg = read_op(); |
| 2350 | UINT16 res; |
| 2351 | |
| 2352 | do |
| 2353 | { |
| 2354 | res = mem_readbyte(REG_UA>>4, REG_IX) - READ_REG(arg); |
| 2355 | |
| 2356 | if (REG_IX == REG_IY) |
| 2357 | break; |
| 2358 | |
| 2359 | REG_IX += ((op&1) ? -1 : +1); |
| 2360 | m_icount -= 6; |
| 2361 | } while(res); |
| 2362 | |
| 2363 | CLEAR_FLAGS; |
| 2364 | CHECK_FLAG_Z(res & 0xff); |
| 2365 | CHECK_FLAGB_UZ_LZ(res); |
| 2366 | CHECK_FLAG_C(res, 0xff); |
| 2367 | |
| 2368 | m_icount -= 9; |
| 2369 | } |
| 2370 | break; |
| 2371 | |
| 2372 | case 0xde: //jp |
| 2373 | { |
| 2374 | UINT8 arg = read_op(); |
| 2375 | set_pc(REG_GET16(arg)); |
| 2376 | |
| 2377 | m_icount -= 5; |
| 2378 | } |
| 2379 | break; |
| 2380 | |
| 2381 | case 0xdf: //jp |
| 2382 | { |
| 2383 | UINT8 arg = read_op(); |
| 2384 | UINT16 offset = REG_GET16(arg); |
| 2385 | UINT8 lsb = mem_readbyte(REG_UA>>4, offset+0); |
| 2386 | UINT8 msb = mem_readbyte(REG_UA>>4, offset+1); |
| 2387 | |
| 2388 | set_pc((msb<<8) | lsb); |
| 2389 | |
| 2390 | m_icount -= 5; |
| 2391 | } |
| 2392 | break; |
| 2393 | |
| 2394 | case 0xe0: //stm |
| 2395 | case 0xe2: //stim |
| 2396 | { |
| 2397 | UINT8 arg = read_op(); |
| 2398 | UINT8 arg1 = read_op(); |
| 2399 | UINT16 prev_ir = REG_IX; |
| 2400 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2401 | |
| 2402 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2403 | |
| 2404 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2405 | { |
| 2406 | mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg++)); |
| 2407 | m_icount -= 3; |
| 2408 | } |
| 2409 | |
| 2410 | RESTORE_REG(op, REG_IX, prev_ir); |
| 2411 | |
| 2412 | m_icount -= 5; |
| 2413 | } |
| 2414 | break; |
| 2415 | |
| 2416 | case 0xe1: //stm |
| 2417 | case 0xe3: //stim |
| 2418 | { |
| 2419 | UINT8 arg = read_op(); |
| 2420 | UINT8 arg1 = read_op(); |
| 2421 | UINT16 prev_ir = REG_IZ; |
| 2422 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2423 | |
| 2424 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2425 | |
| 2426 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2427 | { |
| 2428 | mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg++)); |
| 2429 | m_icount -= 3; |
| 2430 | } |
| 2431 | |
| 2432 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 2433 | |
| 2434 | m_icount -= 5; |
| 2435 | } |
| 2436 | break; |
| 2437 | |
| 2438 | case 0xe4: //stdm |
| 2439 | { |
| 2440 | UINT8 arg = read_op(); |
| 2441 | UINT8 arg1 = read_op(); |
| 2442 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2443 | |
| 2444 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2445 | |
| 2446 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2447 | { |
| 2448 | mem_writebyte(REG_UA>>4, REG_IX--, READ_REG(arg--)); |
| 2449 | m_icount -= 3; |
| 2450 | } |
| 2451 | |
| 2452 | REG_IX++;//todo |
| 2453 | |
| 2454 | m_icount -= 3; |
| 2455 | } |
| 2456 | break; |
| 2457 | |
| 2458 | case 0xe5: //stdm |
| 2459 | { |
| 2460 | UINT8 arg = read_op(); |
| 2461 | UINT8 arg1 = read_op(); |
| 2462 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2463 | |
| 2464 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2465 | |
| 2466 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2467 | { |
| 2468 | mem_writebyte(REG_UA>>6, REG_IZ--, READ_REG(arg--)); |
| 2469 | m_icount -= 3; |
| 2470 | } |
| 2471 | |
| 2472 | REG_IZ++; |
| 2473 | |
| 2474 | m_icount -= 3; |
| 2475 | } |
| 2476 | break; |
| 2477 | |
| 2478 | case 0xe6: //phsm |
| 2479 | case 0xe7: //phum |
| 2480 | { |
| 2481 | UINT8 arg = read_op(); |
| 2482 | UINT8 arg1 = read_op(); |
| 2483 | |
| 2484 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2485 | { |
| 2486 | push((op&1) ? REG_US : REG_SS, READ_REG(arg--)); |
| 2487 | |
| 2488 | m_icount -= 3; |
| 2489 | } |
| 2490 | |
| 2491 | m_icount -= 3; |
| 2492 | } |
| 2493 | break; |
| 2494 | |
| 2495 | case 0xe8: //ldm |
| 2496 | case 0xea: //ldim |
| 2497 | { |
| 2498 | UINT8 arg = read_op(); |
| 2499 | UINT8 arg1 = read_op(); |
| 2500 | UINT16 prev_ir = REG_IX; |
| 2501 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2502 | |
| 2503 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2504 | |
| 2505 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2506 | { |
| 2507 | WRITE_REG(arg++, mem_readbyte(REG_UA>>4, REG_IX++)); |
| 2508 | m_icount -= 3; |
| 2509 | } |
| 2510 | |
| 2511 | RESTORE_REG(op, REG_IX, prev_ir); |
| 2512 | |
| 2513 | m_icount -= 5; |
| 2514 | } |
| 2515 | break; |
| 2516 | |
| 2517 | case 0xe9: //ldm |
| 2518 | case 0xeb: //ldim |
| 2519 | { |
| 2520 | UINT8 arg = read_op(); |
| 2521 | UINT8 arg1 = read_op(); |
| 2522 | UINT16 prev_ir = REG_IZ; |
| 2523 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2524 | |
| 2525 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2526 | |
| 2527 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2528 | { |
| 2529 | WRITE_REG(arg++, mem_readbyte(REG_UA>>6, REG_IZ++)); |
| 2530 | m_icount -= 3; |
| 2531 | } |
| 2532 | |
| 2533 | RESTORE_REG(op, REG_IZ, prev_ir); |
| 2534 | |
| 2535 | m_icount -= 5; |
| 2536 | } |
| 2537 | break; |
| 2538 | |
| 2539 | case 0xec: //lddm |
| 2540 | { |
| 2541 | UINT8 arg = read_op(); |
| 2542 | UINT8 arg1 = read_op(); |
| 2543 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2544 | |
| 2545 | REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2546 | |
| 2547 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2548 | { |
| 2549 | WRITE_REG(arg--, mem_readbyte(REG_UA>>4, REG_IX--)); |
| 2550 | m_icount -= 3; |
| 2551 | } |
| 2552 | |
| 2553 | REG_IX++; |
| 2554 | |
| 2555 | m_icount -= 3; |
| 2556 | } |
| 2557 | break; |
| 2558 | |
| 2559 | case 0xed: //lddm |
| 2560 | { |
| 2561 | UINT8 arg = read_op(); |
| 2562 | UINT8 arg1 = read_op(); |
| 2563 | UINT8 ir_inc = READ_REG(get_sir_im8(arg, arg1)); |
| 2564 | |
| 2565 | REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); |
| 2566 | |
| 2567 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2568 | { |
| 2569 | WRITE_REG(arg--, mem_readbyte(REG_UA>>6, REG_IZ--)); |
| 2570 | m_icount -= 3; |
| 2571 | } |
| 2572 | |
| 2573 | REG_IZ++; |
| 2574 | |
| 2575 | m_icount -= 3; |
| 2576 | } |
| 2577 | break; |
| 2578 | |
| 2579 | case 0xee: //ppsm |
| 2580 | case 0xef: //ppum |
| 2581 | { |
| 2582 | UINT8 arg = read_op(); |
| 2583 | UINT8 arg1 = read_op(); |
| 2584 | |
| 2585 | for (int n=GET_IM3(arg1); n>0; n--) |
| 2586 | { |
| 2587 | WRITE_REG(arg++, pop((op&1) ? REG_US : REG_SS)); |
| 2588 | m_icount -= 3; |
| 2589 | } |
| 2590 | |
| 2591 | m_icount -= 5; |
| 2592 | } |
| 2593 | break; |
| 2594 | |
| 2595 | case 0xf0: //rtn z |
| 2596 | case 0xf1: //rtn nc |
| 2597 | case 0xf2: //rtn lz |
| 2598 | case 0xf3: //rtn uz |
| 2599 | case 0xf4: //rtn nz |
| 2600 | case 0xf5: //rtn c |
| 2601 | case 0xf6: //rtn nlz |
| 2602 | case 0xf7: //unconditional rtn |
| 2603 | { |
| 2604 | if (check_cond(op)) |
| 2605 | { |
| 2606 | UINT8 lsb = pop(REG_SS) ; |
| 2607 | UINT8 msb = pop(REG_SS); |
| 2608 | |
| 2609 | set_pc((((msb<<8) | (lsb<<0)) + 1)); |
| 2610 | } |
| 2611 | m_icount -= 3; |
| 2612 | } |
| 2613 | break; |
| 2614 | |
| 2615 | case 0xf8: //nop |
| 2616 | m_icount -= 3; |
| 2617 | break; |
| 2618 | |
| 2619 | case 0xf9: //clt |
| 2620 | REG_TM = 0; |
| 2621 | m_icount -= 3; |
| 2622 | break; |
| 2623 | |
| 2624 | case 0xfa: //fst |
| 2625 | m_state |= CPU_FAST; |
| 2626 | m_icount -= 3; |
| 2627 | break; |
| 2628 | |
| 2629 | case 0xfb: //slw |
| 2630 | m_state &= ~CPU_FAST; |
| 2631 | m_icount -= 3; |
| 2632 | break; |
| 2633 | |
| 2634 | case 0xfd: //rtni |
| 2635 | { |
| 2636 | UINT8 lsb = pop(REG_SS); |
| 2637 | UINT8 msb = pop(REG_SS); |
| 2638 | |
| 2639 | set_pc((msb<<8) | (lsb<<0)); |
| 2640 | |
| 2641 | m_icount -= 5; |
| 2642 | } |
| 2643 | //fall through |
| 2644 | |
| 2645 | case 0xfc: //cani |
| 2646 | { |
| 2647 | for (UINT8 arg=0x10; arg>0; arg>>=1) |
| 2648 | { |
| 2649 | if (REG_IB & arg) |
| 2650 | { |
| 2651 | REG_IB &= (~arg); |
| 2652 | m_irq_status &= (~arg); |
| 2653 | break; |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | m_icount -= 3; |
| 2658 | } |
| 2659 | break; |
| 2660 | |
| 2661 | case 0xfe: //off |
| 2662 | { |
| 2663 | set_pc(0); |
| 2664 | REG_UA = REG_IA = 0; |
| 2665 | REG_IX = REG_IY = REG_IZ = 0; |
| 2666 | REG_PE = 0; |
| 2667 | REG_IE = (REG_IE&0x0c) | ((REG_IB>1) & 0x10); |
| 2668 | REG_IB &= 0xe3; |
| 2669 | if (m_flags & FLAG_SW) |
| 2670 | m_flags |= FLAG_APO; |
| 2671 | else |
| 2672 | m_flags &= ~FLAG_APO; |
| 2673 | |
| 2674 | m_state |= CPU_SLP; |
| 2675 | |
| 2676 | m_irq_status = 0; |
| 2677 | if (m_cpu_config.m_lcd_control) |
| 2678 | (*m_cpu_config.m_lcd_control)(*this, 0); |
| 2679 | |
| 2680 | if (m_cpu_config.m_kb_w) |
| 2681 | (*m_cpu_config.m_kb_w)(*this, 0); |
| 2682 | m_icount -= 3; |
| 2683 | } |
| 2684 | break; |
| 2685 | |
| 2686 | case 0xff: //trp |
| 2687 | { |
| 2688 | m_pc--; |
| 2689 | push(REG_SS, (m_pc>>8)&0xff); |
| 2690 | push(REG_SS, (m_pc>>0)&0xff); |
| 2691 | set_pc(0x0022); |
| 2692 | m_icount -= 9; |
| 2693 | } |
| 2694 | break; |
| 2695 | |
| 2696 | case 0x03: |
| 2697 | case 0x19: |
| 2698 | case 0x43: |
| 2699 | case 0x53: |
| 2700 | case 0x5a: |
| 2701 | case 0x5b: |
| 2702 | case 0x5e: |
| 2703 | case 0x5f: |
| 2704 | case 0x66: |
| 2705 | case 0x67: |
| 2706 | case 0x6e: |
| 2707 | case 0x6f: |
| 2708 | case 0x83: |
| 2709 | case 0x94: |
| 2710 | case 0x95: |
| 2711 | case 0x99: |
| 2712 | case 0x9d: |
| 2713 | case 0xc3: |
| 2714 | case 0xd4: |
| 2715 | case 0xd5: |
| 2716 | logerror( "%06x: illegal instruction %02x encountered\n", m_pc, op ); |
| 2717 | break; |
| 2718 | |
| 2719 | default: |
| 2720 | logerror( "%06x: unimplemented instruction %02x encountered\n", m_pc, op ); |
| 2721 | break; |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | //if is in the internal ROM align the pc |
| 2726 | if ((m_fetch_addr&1) && m_pc < INT_ROM) |
| 2727 | set_pc((m_fetch_addr+1)>>1); |
| 2728 | |
| 2729 | m_icount -= 3; |
| 2730 | } while (m_icount > 0); |
| 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | //------------------------------------------------- |
| 2735 | // execute_set_input |
| 2736 | //------------------------------------------------- |
| 2737 | |
| 2738 | void hd61700_cpu_device::execute_set_input(int inputnum, int state) |
| 2739 | { |
| 2740 | switch (inputnum) |
| 2741 | { |
| 2742 | case INPUT_LINE_RESET: |
| 2743 | REG_UA = 0; |
| 2744 | REG_IA = 0; |
| 2745 | REG_IX = 0; |
| 2746 | REG_IY = 0; |
| 2747 | REG_IZ = 0; |
| 2748 | REG_PE = 0; |
| 2749 | REG_IE = 0; |
| 2750 | REG_IB = 0; |
| 2751 | m_state &= ~(CPU_SLP | CPU_FAST); |
| 2752 | set_pc(0x0000); |
| 2753 | break; |
| 2754 | case HD61700_KEY_INT: //level sensitive line |
| 2755 | if (((REG_IE>>3) & (1<<inputnum)) && state != CLEAR_LINE) |
| 2756 | REG_IB |= (1<<inputnum); |
| 2757 | break; |
| 2758 | |
| 2759 | case HD61700_INT1: //edge sensitive line |
| 2760 | if (((REG_IE>>3) & (1<<inputnum)) && (m_lines_status[inputnum] != state)) |
| 2761 | REG_IB |= (1<<inputnum); |
| 2762 | |
| 2763 | if (m_lines_status[inputnum] == CLEAR_LINE && state != CLEAR_LINE) |
| 2764 | REG_IE = (REG_IE & 0xfd) | 0x02; //rising edge |
| 2765 | else if (m_lines_status[inputnum] != CLEAR_LINE && state == CLEAR_LINE) |
| 2766 | REG_IE = (REG_IE & 0xfd) | 0x00; //falling edge |
| 2767 | |
| 2768 | REG_KY = (REG_KY & 0xf7ff) | ((state != CLEAR_LINE)<<11); |
| 2769 | break; |
| 2770 | case HD61700_INT2: //level sensitive line |
| 2771 | if (((REG_IE>>3) & (1<<inputnum)) && state != CLEAR_LINE) |
| 2772 | REG_IB |= (1<<inputnum); |
| 2773 | |
| 2774 | REG_IE = (REG_IE & 0xfe) | (state != CLEAR_LINE); |
| 2775 | REG_KY = (REG_KY & 0xfbff) | ((state != CLEAR_LINE)<<10); |
| 2776 | break; |
| 2777 | case HD61700_ON_INT: //level sensitive line |
| 2778 | if ((REG_IE>>3) & (1<<inputnum) && state != CLEAR_LINE) |
| 2779 | REG_IB |= (1<<inputnum); |
| 2780 | |
| 2781 | REG_KY = (REG_KY & 0xfdff) | ((state != CLEAR_LINE)<<9); |
| 2782 | break; |
| 2783 | |
| 2784 | case HD61700_SW: //level sensitive line |
| 2785 | if (state != CLEAR_LINE) |
| 2786 | { |
| 2787 | if ((m_state & CPU_SLP) || m_lines_status[HD61700_SW] == CLEAR_LINE) |
| 2788 | { |
| 2789 | m_state &= ~(CPU_SLP | CPU_FAST); |
| 2790 | m_flags &= ~FLAG_APO; |
| 2791 | set_pc(0x0001); |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | m_flags |= ((state != CLEAR_LINE)<<3); |
| 2796 | break; |
| 2797 | } |
| 2798 | |
| 2799 | m_lines_status[inputnum] = state; |
| 2800 | } |
| 2801 | |
| 2802 | |
| 2803 | //************************************************************************** |
| 2804 | // INLINE HELPERS |
| 2805 | //************************************************************************** |
| 2806 | |
| 2807 | inline void hd61700_cpu_device::set_pc(INT32 new_pc) |
| 2808 | { |
| 2809 | m_curpc = (m_curpc & 0x30000) | new_pc; |
| 2810 | m_pc = new_pc & 0xffff; |
| 2811 | m_fetch_addr = new_pc<<1; |
| 2812 | } |
| 2813 | |
| 2814 | inline UINT8 hd61700_cpu_device::read_op() |
| 2815 | { |
| 2816 | UINT16 data = 0; |
| 2817 | UINT32 addr18 = make_18bit_addr((m_irq_status) ? 0 : prev_ua, m_pc); |
| 2818 | |
| 2819 | if (m_pc <= INT_ROM) |
| 2820 | { |
| 2821 | data = m_program->read_word(addr18<<1); |
| 2822 | |
| 2823 | if (!(m_fetch_addr&1)) |
| 2824 | data = (data>>8) ; |
| 2825 | } |
| 2826 | else |
| 2827 | { |
| 2828 | if (m_fetch_addr&1) |
| 2829 | data = m_program->read_word((addr18+1)<<1); |
| 2830 | else |
| 2831 | data = m_program->read_word((addr18+0)<<1); |
| 2832 | } |
| 2833 | |
| 2834 | m_fetch_addr += ((m_pc > INT_ROM) ? 2 : 1); |
| 2835 | |
| 2836 | m_pc = m_fetch_addr>>1; |
| 2837 | |
| 2838 | m_curpc = make_18bit_addr((m_irq_status) ? 0 : prev_ua, m_pc); |
| 2839 | |
| 2840 | prev_ua = REG_UA; |
| 2841 | |
| 2842 | return (data&0xff); |
| 2843 | } |
| 2844 | |
| 2845 | inline UINT8 hd61700_cpu_device::mem_readbyte(UINT8 segment, UINT16 offset) |
| 2846 | { |
| 2847 | return m_program->read_word(make_18bit_addr(segment, offset)<<1) & 0xff; |
| 2848 | } |
| 2849 | |
| 2850 | inline void hd61700_cpu_device::mem_writebyte(UINT8 segment, UINT16 offset, UINT8 data) |
| 2851 | { |
| 2852 | m_program->write_word(make_18bit_addr(segment, offset)<<1, data); |
| 2853 | } |
| 2854 | |
| 2855 | inline UINT32 hd61700_cpu_device::make_18bit_addr(UINT8 segment, UINT16 offset) |
| 2856 | { |
| 2857 | if (offset >= ((REG_IB>>6) & 0x03) * 0x4000) |
| 2858 | return (UINT32)((offset | ((segment&0x03)<<16)) & 0x3ffff); |
| 2859 | else |
| 2860 | return offset; |
| 2861 | } |
| 2862 | |
| 2863 | inline void hd61700_cpu_device::push(UINT16 &offset, UINT8 data) |
| 2864 | { |
| 2865 | offset--; |
| 2866 | mem_writebyte(REG_UA>>2, offset, data); |
| 2867 | } |
| 2868 | |
| 2869 | inline UINT8 hd61700_cpu_device::pop(UINT16 &offset) |
| 2870 | { |
| 2871 | UINT8 data = mem_readbyte(REG_UA>>2, offset); |
| 2872 | offset++; |
| 2873 | return data; |
| 2874 | } |
| 2875 | |
| 2876 | inline int hd61700_cpu_device::check_cond(UINT32 op) |
| 2877 | { |
| 2878 | switch ( op & 0x07 ) |
| 2879 | { |
| 2880 | case 0x00: // Z set |
| 2881 | if ( !(m_flags & FLAG_Z) ) |
| 2882 | return 1; |
| 2883 | break; |
| 2884 | |
| 2885 | case 0x01: // NC set |
| 2886 | if ( !(m_flags & FLAG_C) ) |
| 2887 | return 1; |
| 2888 | break; |
| 2889 | |
| 2890 | case 0x02: // LZ set |
| 2891 | if ( !(m_flags & FLAG_LZ) ) |
| 2892 | return 1; |
| 2893 | break; |
| 2894 | |
| 2895 | case 0x03: // UZ set |
| 2896 | if ( !(m_flags & FLAG_UZ) ) |
| 2897 | return 1; |
| 2898 | break; |
| 2899 | |
| 2900 | case 0x04: // NZ set |
| 2901 | if ( m_flags & FLAG_Z ) |
| 2902 | return 1; |
| 2903 | break; |
| 2904 | |
| 2905 | case 0x05: // C set |
| 2906 | if ( m_flags & FLAG_C ) |
| 2907 | return 1; |
| 2908 | break; |
| 2909 | |
| 2910 | case 0x06: // NLZ clear |
| 2911 | if ( m_flags & FLAG_LZ ) |
| 2912 | return 1; |
| 2913 | break; |
| 2914 | |
| 2915 | case 0x07: // unconditional |
| 2916 | return 1; |
| 2917 | break; |
| 2918 | } |
| 2919 | |
| 2920 | return 0; |
| 2921 | } |
| 2922 | |
| 2923 | inline UINT8 hd61700_cpu_device::make_logic(UINT8 type, UINT8 d1, UINT8 d2) |
| 2924 | { |
| 2925 | switch (type&3) |
| 2926 | { |
| 2927 | case 0: //and |
| 2928 | return d1 & d2; |
| 2929 | case 1: //nand |
| 2930 | return ~(d1 & d2); |
| 2931 | case 2: //or |
| 2932 | return d1 | d2; |
| 2933 | case 3: //xor |
| 2934 | return d1 ^ d2; |
| 2935 | default: |
| 2936 | return 0x00; |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | inline void hd61700_cpu_device::check_optional_jr(UINT8 arg) |
| 2941 | { |
| 2942 | if (arg & 0x80) |
| 2943 | { |
| 2944 | if (m_pc < INT_ROM && !(m_fetch_addr&1)) read_op(); |
| 2945 | |
| 2946 | UINT8 arg1 = read_op(); |
| 2947 | |
| 2948 | UINT32 new_pc = m_pc + get_im_7(arg1) - 1; |
| 2949 | |
| 2950 | set_pc(new_pc); |
| 2951 | m_icount -= 3; |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | inline UINT8 hd61700_cpu_device::get_sir_im8(UINT8 arg) |
| 2956 | { |
| 2957 | if (((arg>>5) & 0x03) == 0x03) |
| 2958 | { |
| 2959 | UINT8 arg1 = read_op(); |
| 2960 | |
| 2961 | return arg1&0x1f; |
| 2962 | } |
| 2963 | else |
| 2964 | { |
| 2965 | return READ_SREG(arg)&0x1f; |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | inline UINT8 hd61700_cpu_device::get_sir_im8(UINT8 arg, UINT8 arg1) |
| 2970 | { |
| 2971 | if (((arg>>5) & 0x03) == 0x03) |
| 2972 | { |
| 2973 | return arg1&0x1f; |
| 2974 | } |
| 2975 | else |
| 2976 | { |
| 2977 | return READ_SREG(arg)&0x1f; |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | inline int hd61700_cpu_device::get_sign_mreg(UINT8 arg) |
| 2982 | { |
| 2983 | int res = READ_REG(get_sir_im8(arg)); |
| 2984 | |
| 2985 | if (arg & 0x80) res = -res; |
| 2986 | |
| 2987 | return res; |
| 2988 | } |
| 2989 | |
| 2990 | inline int hd61700_cpu_device::get_sign_im8(UINT8 arg) |
| 2991 | { |
| 2992 | int res = read_op(); |
| 2993 | |
| 2994 | if (arg & 0x80) res = -res; |
| 2995 | |
| 2996 | return res; |
| 2997 | } |
| 2998 | |
| 2999 | inline int hd61700_cpu_device::get_im_7(UINT8 data) |
| 3000 | { |
| 3001 | if (data&0x80) |
| 3002 | return 0x80 - data; |
| 3003 | else |
| 3004 | return data; |
| 3005 | } |
| 3006 | |
| 3007 | inline UINT16 hd61700_cpu_device::make_bcd_sub(UINT8 arg1, UINT8 arg2) |
| 3008 | { |
| 3009 | |
| 3010 | UINT32 ret = (arg1&0x0f) - (arg2&0x0f); |
| 3011 | UINT8 carry; |
| 3012 | |
| 3013 | if (ret > 0x09) |
| 3014 | { |
| 3015 | ret = (ret - 0x06) & 0x0f; |
| 3016 | carry = 1; |
| 3017 | } |
| 3018 | else |
| 3019 | carry = 0; |
| 3020 | |
| 3021 | ret += ((arg1&0xf0) - (arg2&0xf0) - (carry<<4)); |
| 3022 | |
| 3023 | if (ret > 0x9f) |
| 3024 | { |
| 3025 | ret = (ret - 0x60) & 0x0ff; |
| 3026 | carry = 1; |
| 3027 | } |
| 3028 | else |
| 3029 | carry = 0; |
| 3030 | |
| 3031 | ret -= (carry<<8); |
| 3032 | |
| 3033 | return ret; |
| 3034 | } |
| 3035 | |
| 3036 | inline UINT16 hd61700_cpu_device::make_bcd_add(UINT8 arg1, UINT8 arg2) |
| 3037 | { |
| 3038 | UINT32 ret = (arg1&0x0f) + (arg2&0x0f); |
| 3039 | UINT8 carry; |
| 3040 | |
| 3041 | if (ret > 0x09) |
| 3042 | { |
| 3043 | ret = (ret + 0x06) & 0x0f; |
| 3044 | carry = 1; |
| 3045 | } |
| 3046 | else |
| 3047 | carry = 0; |
| 3048 | |
| 3049 | ret += ((arg1&0xf0) + (arg2&0xf0) + (carry<<4)); |
| 3050 | |
| 3051 | if (ret > 0x9f) |
| 3052 | { |
| 3053 | ret = (ret + 0x60) & 0x0ff; |
| 3054 | carry = 1; |
| 3055 | } |
| 3056 | else |
| 3057 | carry = 0; |
| 3058 | |
| 3059 | ret += (carry<<8); |
| 3060 | |
| 3061 | return ret; |
| 3062 | } |
src/emu/cpu/hd61700/hd61700d.c
| r0 | r9924 | |
| 1 | #include "emu.h" |
| 2 | #include "debugger.h" |
| 3 | #include "hd61700.h" |
| 4 | |
| 5 | #define EXT_ROM (pc > 0x0c00) |
| 6 | #define INC_POS pos += (type+1) |
| 7 | #define POS (pos + type) |
| 8 | |
| 9 | static const char *const reg_5b[4] = {"sx", "sy", "sz", "sz"}; |
| 10 | static const char *const reg_8b[8] = {"pe", "pd", "ib", "ua", "ia", "ie", "tm", "tm"}; |
| 11 | static const char *const reg_16b[8] = {"ix", "iy", "iz", "us", "ss", "ky", "ky", "ky"}; |
| 12 | static const char *const jp_cond[8] = {"z", "nc", "lz", "uz", "nz", "c", "nlz"}; |
| 13 | |
| 14 | enum |
| 15 | { |
| 16 | OP_NULL=0, |
| 17 | OP_IM16, |
| 18 | OP_IM16A, |
| 19 | OP_IM3, |
| 20 | OP_IM5, |
| 21 | OP_IM7, |
| 22 | OP_IM8, |
| 23 | OP_IM8I, |
| 24 | OP_IM8_, |
| 25 | OP_IR_IM3, |
| 26 | OP_IR_IM8, |
| 27 | OP_IR_IM8_, |
| 28 | OP_JX_COND, |
| 29 | OP_MREG, |
| 30 | OP_MREG2, |
| 31 | OP_MR_SIR, |
| 32 | OP_MR_SIRI, |
| 33 | OP_REG16, |
| 34 | OP_REG16_, |
| 35 | OP_REG8, |
| 36 | OP_REG8_, |
| 37 | OP_REGIM8, |
| 38 | OP_RMSIM3, |
| 39 | OP_RSIR, |
| 40 | }; |
| 41 | |
| 42 | typedef struct |
| 43 | { |
| 44 | const char *str; |
| 45 | UINT8 arg1; |
| 46 | UINT8 arg2; |
| 47 | bool optjr; |
| 48 | } hd61700_dasm; |
| 49 | |
| 50 | static const hd61700_dasm hd61700_ops[256] = |
| 51 | { |
| 52 | // 0x00 |
| 53 | { "adc", OP_MREG, OP_MR_SIR, 1 }, { "sbc", OP_MREG, OP_MR_SIR, 1 }, |
| 54 | { "ld", OP_MREG, OP_MR_SIR, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 55 | { "anc", OP_MREG, OP_MR_SIR, 1 }, { "nac", OP_MREG, OP_MR_SIR, 1 }, |
| 56 | { "orc", OP_MREG, OP_MR_SIR, 1 }, { "xrc", OP_MREG, OP_MR_SIR, 1 }, |
| 57 | { "ad", OP_MREG, OP_MR_SIR, 1 }, { "sb", OP_MREG, OP_MR_SIR, 1 }, |
| 58 | { "adb", OP_MREG, OP_MR_SIR, 1 }, { "sbb", OP_MREG, OP_MR_SIR, 1 }, |
| 59 | { "an", OP_MREG, OP_MR_SIR, 1 }, { "na", OP_MREG, OP_MR_SIR, 1 }, |
| 60 | { "or", OP_MREG, OP_MR_SIR, 1 }, { "xr", OP_MREG, OP_MR_SIR, 1 }, |
| 61 | |
| 62 | // 0x10 |
| 63 | { "st", OP_MREG, OP_MR_SIRI, 1 }, { "ld", OP_MREG, OP_MR_SIRI,1 }, |
| 64 | { "stl", OP_MREG2, OP_NULL, 1 }, { "ldl", OP_MREG2, OP_NULL, 1 }, |
| 65 | { "???", OP_MREG2, OP_NULL, 1 }, { "psr", OP_RSIR, OP_MREG2, 1 }, |
| 66 | { "pst", OP_REG8, OP_MREG2, 1 }, { "pst", OP_REG8, OP_MREG2, 1 }, |
| 67 | { "???", OP_MREG2, OP_NULL, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 68 | { "???", OP_MREG2, OP_NULL, 1 }, { "???", OP_MREG2, OP_NULL, 1 }, |
| 69 | { "???", OP_MREG2, OP_NULL, 1 }, { "gsr", OP_RSIR, OP_MREG2, 1 }, |
| 70 | { "gst", OP_REG8, OP_MREG2, 1 }, { "gst", OP_REG8, OP_MREG2, 1 }, |
| 71 | |
| 72 | // 0x20 |
| 73 | { "st", OP_MREG, OP_IR_IM8_, 0 }, { "st", OP_MREG, OP_IR_IM8_,0 }, |
| 74 | { "sti", OP_MREG, OP_IR_IM8_, 0 }, { "sti", OP_MREG, OP_IR_IM8_,0 }, |
| 75 | { "std", OP_MREG, OP_IR_IM8_, 0 }, { "std", OP_MREG, OP_IR_IM8_,0 }, |
| 76 | { "phs", OP_MREG2, OP_NULL, 0 }, { "phu", OP_MREG2, OP_NULL, 0 }, |
| 77 | { "ld", OP_MREG, OP_IR_IM8_, 0 }, { "ld", OP_MREG, OP_IR_IM8_,0 }, |
| 78 | { "ldi", OP_MREG, OP_IR_IM8_, 0 }, { "ldi", OP_MREG, OP_IR_IM8_,0 }, |
| 79 | { "ldd", OP_MREG, OP_IR_IM8_, 0 }, { "ldd", OP_MREG, OP_IR_IM8_,0 }, |
| 80 | { "pps", OP_MREG2, OP_NULL, 0 }, { "ppu", OP_MREG2, OP_NULL, 0 }, |
| 81 | |
| 82 | // 0x30 |
| 83 | { "jp", OP_JX_COND, OP_IM16A, 0 }, { "jp", OP_JX_COND, OP_IM16A, 0 }, |
| 84 | { "jp", OP_JX_COND, OP_IM16A, 0 }, { "jp", OP_JX_COND, OP_IM16A, 0 }, |
| 85 | { "jp", OP_JX_COND, OP_IM16A, 0 }, { "jp", OP_JX_COND, OP_IM16A, 0 }, |
| 86 | { "jp", OP_JX_COND, OP_IM16A, 0 }, { "jp", OP_IM16A, OP_NULL, 0 }, |
| 87 | { "adc", OP_IR_IM8, OP_MREG2, 0 }, { "adc", OP_IR_IM8, OP_MREG2, 0 }, |
| 88 | { "sbc", OP_IR_IM8, OP_MREG2, 0 }, { "sbc", OP_IR_IM8, OP_MREG2, 0 }, |
| 89 | { "ad", OP_IR_IM8, OP_MREG2, 0 }, { "ad", OP_IR_IM8, OP_MREG2, 0 }, |
| 90 | { "sb", OP_IR_IM8, OP_MREG2, 0 }, { "sb", OP_IR_IM8, OP_MREG2, 0 }, |
| 91 | |
| 92 | // 0x40 |
| 93 | { "adc", OP_MREG2, OP_IM8, 1 }, { "sbc", OP_MREG2, OP_IM8, 1 }, |
| 94 | { "ld", OP_MREG2, OP_IM8, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 95 | { "anc", OP_MREG2, OP_IM8, 1 }, { "nac", OP_MREG2, OP_IM8, 1 }, |
| 96 | { "orc", OP_MREG2, OP_IM8, 1 }, { "xrc", OP_MREG2, OP_IM8, 1 }, |
| 97 | { "ad", OP_MREG2, OP_IM8, 1 }, { "sb", OP_MREG2, OP_IM8, 1 }, |
| 98 | { "adb", OP_MREG2, OP_IM8, 1 }, { "sbb", OP_MREG2, OP_IM8, 1 }, |
| 99 | { "an", OP_MREG2, OP_IM8, 1 }, { "na", OP_MREG2, OP_IM8, 1 }, |
| 100 | { "or", OP_MREG2, OP_IM8, 1 }, { "xr", OP_MREG2, OP_IM8, 1 }, |
| 101 | |
| 102 | // 0x50 |
| 103 | { "st", OP_IM8I, OP_MREG2, 0 }, { "st", OP_IM8, OP_MREG2,0 }, |
| 104 | { "stl", OP_IM8_, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 105 | { "???", OP_IM8_, OP_NULL, 0 }, { "psr", OP_RSIR, OP_IM5, 0 }, |
| 106 | { "pst", OP_REG8_, OP_IM8, 0 }, { "pst", OP_REG8_, OP_IM8, 0 }, |
| 107 | { "bups", OP_IM8_, OP_NULL, 0 }, { "bdns", OP_IM8_, OP_NULL, 0 }, |
| 108 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 109 | { "sup", OP_IM8_, OP_NULL, 0 }, { "sdn", OP_IM8_, OP_NULL, 0 }, |
| 110 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 111 | |
| 112 | // 0x60 |
| 113 | { "st", OP_MREG2, OP_REGIM8, 0 }, { "st", OP_MREG2, OP_REGIM8, 0 }, |
| 114 | { "sti", OP_MREG2, OP_REGIM8, 0 }, { "sti", OP_MREG2, OP_REGIM8, 0 }, |
| 115 | { "std", OP_MREG2, OP_REGIM8, 0 }, { "std", OP_MREG2, OP_REGIM8, 0 }, |
| 116 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 117 | { "ld", OP_MREG2, OP_REGIM8, 0 }, { "ld", OP_MREG2, OP_REGIM8, 0 }, |
| 118 | { "ldi", OP_MREG2, OP_REGIM8, 0 }, { "ldi", OP_MREG2, OP_REGIM8, 0 }, |
| 119 | { "ldd", OP_MREG2, OP_REGIM8, 0 }, { "ldd", OP_MREG2, OP_REGIM8, 0 }, |
| 120 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 121 | |
| 122 | // 0x70 |
| 123 | { "cal", OP_JX_COND, OP_IM16A, 0 }, { "cal", OP_JX_COND, OP_IM16A, 0 }, |
| 124 | { "cal", OP_JX_COND, OP_IM16A, 0 }, { "cal", OP_JX_COND, OP_IM16A, 0 }, |
| 125 | { "cal", OP_JX_COND, OP_IM16A, 0 }, { "cal", OP_JX_COND, OP_IM16A, 0 }, |
| 126 | { "cal", OP_JX_COND, OP_IM16A, 0 }, { "cal", OP_IM16A, OP_NULL, 0 }, |
| 127 | { "adc", OP_REGIM8, OP_MREG2, 0 }, { "adc", OP_REGIM8, OP_MREG2, 0 }, |
| 128 | { "sbc", OP_REGIM8, OP_MREG2, 0 }, { "sbc", OP_REGIM8, OP_MREG2, 0 }, |
| 129 | { "ad", OP_REGIM8, OP_MREG2, 0 }, { "ad ", OP_REGIM8, OP_MREG2, 0 }, |
| 130 | { "sb", OP_REGIM8, OP_MREG2, 0 }, { "sb", OP_REGIM8, OP_MREG2, 0 }, |
| 131 | |
| 132 | // 0x80 |
| 133 | { "adcw", OP_MREG, OP_MR_SIR, 1 }, { "sbcw", OP_MREG, OP_MR_SIR, 1 }, |
| 134 | { "ldw", OP_MREG, OP_MR_SIR, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 135 | { "ancw", OP_MREG, OP_MR_SIR, 1 }, { "nacw", OP_MREG, OP_MR_SIR, 1 }, |
| 136 | { "orcw", OP_MREG, OP_MR_SIR, 1 }, { "xrcw", OP_MREG, OP_MR_SIR, 1 }, |
| 137 | { "adw", OP_MREG, OP_MR_SIR, 1 }, { "sbw", OP_MREG, OP_MR_SIR, 1 }, |
| 138 | { "adbw", OP_MREG, OP_MR_SIR, 1 }, { "sbbw", OP_MREG, OP_MR_SIR, 1 }, |
| 139 | { "anw", OP_MREG, OP_MR_SIR, 1 }, { "naw", OP_MREG, OP_MR_SIR, 1 }, |
| 140 | { "orw", OP_MREG, OP_MR_SIR, 1 }, { "xrw", OP_MREG, OP_MR_SIR, 1 }, |
| 141 | |
| 142 | // 0x90 |
| 143 | { "stw", OP_MREG, OP_MR_SIRI,1 }, { "ldw", OP_MREG, OP_MR_SIRI,1 }, |
| 144 | { "stlw", OP_MREG2, OP_NULL, 1 }, { "ldlw", OP_MREG2, OP_NULL, 1 }, |
| 145 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 146 | { "pre", OP_REG16, OP_MREG2, 1 }, { "pre", OP_REG16, OP_MREG2, 1 }, |
| 147 | { "???", OP_MREG2, OP_NULL, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 148 | { "???", OP_MREG2, OP_NULL, 1 }, { "???", OP_MREG2, OP_NULL, 1 }, |
| 149 | { "???", OP_MREG2, OP_NULL, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 150 | { "gre", OP_REG16, OP_MREG2, 1 }, { "gre", OP_REG16, OP_MREG2, 1 }, |
| 151 | |
| 152 | // 0xa0 |
| 153 | { "stw", OP_MREG, OP_IR_IM8_, 0 }, { "stw", OP_MREG, OP_IR_IM8_, 0 }, |
| 154 | { "stiw", OP_MREG, OP_IR_IM8_, 0 }, { "stiw", OP_MREG, OP_IR_IM8_, 0 }, |
| 155 | { "stdw", OP_MREG, OP_IR_IM8_, 0 }, { "stdw", OP_MREG, OP_IR_IM8_, 0 }, |
| 156 | { "phsw", OP_MREG2, OP_NULL, 0 }, { "phuw", OP_MREG2, OP_NULL, 0 }, |
| 157 | { "ldw", OP_MREG, OP_IR_IM8_, 0 }, { "ldw", OP_MREG, OP_IR_IM8_, 0 }, |
| 158 | { "ldiw", OP_MREG, OP_IR_IM8_, 0 }, { "ldiw", OP_MREG, OP_IR_IM8_, 0 }, |
| 159 | { "lddw", OP_MREG, OP_IR_IM8_, 0 }, { "lddw", OP_MREG, OP_IR_IM8_, 0 }, |
| 160 | { "ppsw", OP_MREG2, OP_NULL, 0 }, { "ppuw", OP_MREG2, OP_NULL, 0 }, |
| 161 | |
| 162 | // 0xb0 |
| 163 | { "jr", OP_JX_COND, OP_IM7, 0 }, { "jr", OP_JX_COND, OP_IM7, 0 }, |
| 164 | { "jr", OP_JX_COND, OP_IM7, 0 }, { "jr", OP_JX_COND, OP_IM7, 0 }, |
| 165 | { "jr", OP_JX_COND, OP_IM7, 0 }, { "jr", OP_JX_COND, OP_IM7, 0 }, |
| 166 | { "jr", OP_JX_COND, OP_IM7, 0 }, { "jr", OP_IM7, OP_NULL, 0 }, |
| 167 | { "adcw", OP_IR_IM8, OP_MREG, 0 }, { "adcw", OP_IR_IM8, OP_MREG, 0 }, |
| 168 | { "sbcw", OP_IR_IM8, OP_MREG, 0 }, { "sbcw", OP_IR_IM8, OP_MREG, 0 }, |
| 169 | { "adw", OP_IR_IM8, OP_MREG, 0 }, { "adw", OP_IR_IM8, OP_MREG, 0 }, |
| 170 | { "sbw", OP_IR_IM8, OP_MREG, 0 }, { "sbw", OP_IR_IM8, OP_MREG, 0 }, |
| 171 | |
| 172 | // 0xc0 |
| 173 | { "adbcm",OP_MREG, OP_RMSIM3, 1 }, { "sdbcm",OP_MREG, OP_RMSIM3, 1 }, |
| 174 | { "ldm", OP_MREG, OP_RMSIM3, 1 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 175 | { "ancm", OP_MREG, OP_RMSIM3, 1 }, { "nacm", OP_MREG, OP_RMSIM3, 1 }, |
| 176 | { "orcm", OP_MREG, OP_RMSIM3, 1 }, { "xrcm", OP_MREG, OP_RMSIM3, 1 }, |
| 177 | { "adbm", OP_MREG, OP_RMSIM3, 1 }, { "sbbm", OP_MREG, OP_RMSIM3, 1 }, |
| 178 | { "adbm", OP_MREG, OP_RMSIM3, 1 }, { "sbbm", OP_MREG, OP_RMSIM3, 1 }, |
| 179 | { "anm", OP_MREG, OP_RMSIM3, 1 }, { "nam", OP_MREG, OP_RMSIM3, 1 }, |
| 180 | { "orm", OP_MREG, OP_RMSIM3, 1 }, { "xrm", OP_MREG, OP_RMSIM3, 1 }, |
| 181 | |
| 182 | // 0xd0 |
| 183 | { "stw", OP_IM16, OP_MR_SIR, 0 }, { "ldw", OP_MREG2, OP_IM16, 0 }, |
| 184 | { "stlm", OP_MREG2, OP_IM3, 0 }, { "ldlm", OP_MREG2, OP_IM3, 0 }, |
| 185 | { "illegal", OP_NULL, OP_NULL, 0 }, { "illegal", OP_NULL, OP_NULL, 0 }, |
| 186 | { "pre", OP_REG16_, OP_IM16, 0 }, { "pre", OP_REG16_, OP_IM16, 0 }, |
| 187 | { "bup", OP_NULL, OP_NULL, 0 }, { "bnd", OP_NULL, OP_NULL, 0 }, |
| 188 | { "???", OP_MREG2, OP_IM3, 0 }, { "???", OP_MREG2, OP_IM3, 0 }, |
| 189 | { "sup", OP_MREG, OP_NULL, 0 }, { "sdn", OP_MREG, OP_NULL, 0 }, |
| 190 | { "jp", OP_MREG, OP_NULL, 0 }, { "jp", OP_MREG, OP_NULL, 0 }, |
| 191 | |
| 192 | // 0xe0 |
| 193 | { "stm", OP_MREG, OP_IR_IM3, 0 }, { "stm", OP_MREG, OP_IR_IM3, 0 }, |
| 194 | { "stim", OP_MREG, OP_IR_IM3, 0 }, { "stim", OP_MREG, OP_IR_IM3, 0 }, |
| 195 | { "stdm", OP_MREG, OP_IR_IM3, 0 }, { "stdm", OP_MREG, OP_IR_IM3, 0 }, |
| 196 | { "phsm", OP_MREG2, OP_IM3, 0 }, { "phum", OP_MREG2, OP_IM3, 0 }, |
| 197 | { "ldm", OP_MREG, OP_IR_IM3, 0 }, { "ldm", OP_MREG, OP_IR_IM3, 0 }, |
| 198 | { "ldim", OP_MREG, OP_IR_IM3, 0 }, { "ldim", OP_MREG, OP_IR_IM3, 0 }, |
| 199 | { "lddm", OP_MREG, OP_IR_IM3, 0 }, { "lddm", OP_MREG, OP_IR_IM3, 0 }, |
| 200 | { "ppsm", OP_MREG2, OP_IM3, 0 }, { "ppum", OP_MREG2, OP_IM3, 0 }, |
| 201 | |
| 202 | // 0xf0 |
| 203 | { "rtn", OP_JX_COND, OP_NULL, 0 }, { "rtn", OP_JX_COND, OP_NULL, 0 }, |
| 204 | { "rtn", OP_JX_COND, OP_NULL, 0 }, { "rtn", OP_JX_COND, OP_NULL, 0 }, |
| 205 | { "rtn", OP_JX_COND, OP_NULL, 0 }, { "rtn", OP_JX_COND, OP_NULL, 0 }, |
| 206 | { "rtn", OP_JX_COND, OP_NULL, 0 }, { "rtn", OP_NULL, OP_NULL, 0 }, |
| 207 | { "nop", OP_JX_COND, OP_NULL, 0 }, { "clt", OP_NULL, OP_NULL, 0 }, |
| 208 | { "fst", OP_NULL, OP_NULL, 0 }, { "slw", OP_NULL, OP_NULL, 0 }, |
| 209 | { "can", OP_NULL, OP_NULL, 0 }, { "rtni", OP_NULL, OP_NULL, 0 }, |
| 210 | { "off", OP_NULL, OP_NULL, 0 }, { "trp", OP_NULL, OP_NULL, 0 }, |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | inline int dasm_im8(char *buffer, UINT16 pc, int arg, const UINT8 *oprom, int &pos, int type) |
| 215 | { |
| 216 | if (((arg>>5) & 0x03) == 0x03) |
| 217 | { |
| 218 | INC_POS; |
| 219 | UINT8 ret = sprintf( buffer, "0x%02x", oprom[POS] & 0x1f ); |
| 220 | return ret; |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | return sprintf( buffer, "%s", reg_5b[(arg>>5) & 0x03] ); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | |
| 229 | inline int dasm_im8(char *buffer, UINT16 pc, int arg, int arg1, const UINT8 *oprom, int &pos) |
| 230 | { |
| 231 | if (((arg>>5) & 0x03) == 0x03) |
| 232 | { |
| 233 | return sprintf( buffer, "0x%02x", arg1 & 0x1f ); |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | return sprintf( buffer, "%s", reg_5b[(arg>>5) & 0x03] ); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | |
| 242 | int dasm_arg(char *buffer, UINT8 op, UINT16 pc, int arg, const UINT8 *oprom, int &pos) |
| 243 | { |
| 244 | char* buffer_start = buffer; |
| 245 | int type = EXT_ROM; |
| 246 | |
| 247 | switch( arg ) |
| 248 | { |
| 249 | case OP_MREG: |
| 250 | case OP_MREG2: |
| 251 | buffer += sprintf( buffer, "$%02u", oprom[POS] & 0x1f ); |
| 252 | if (arg == OP_MREG2) INC_POS; |
| 253 | break; |
| 254 | |
| 255 | case OP_RSIR: |
| 256 | buffer += sprintf( buffer, "%s", reg_5b[(oprom[POS]>>5) & 0x03] ); |
| 257 | break; |
| 258 | |
| 259 | case OP_REG8: |
| 260 | case OP_REG8_: |
| 261 | buffer += sprintf( buffer, "%s", reg_8b[(BIT(op,0)<<2) + ((oprom[POS]>>5&3))]); |
| 262 | if (arg == OP_REG8_) INC_POS; |
| 263 | break; |
| 264 | |
| 265 | case OP_MR_SIR: |
| 266 | buffer += dasm_im8(buffer, pc, oprom[POS], oprom, pos, type); |
| 267 | INC_POS; |
| 268 | break; |
| 269 | |
| 270 | case OP_IR_IM8: |
| 271 | case OP_IR_IM8_: |
| 272 | buffer += sprintf( buffer, "(%s%s", (op&1) ? "iz": "ix", (oprom[POS]&0x80) ? "-": "+"); |
| 273 | buffer += dasm_im8(buffer, pc, oprom[POS], oprom, pos, type); |
| 274 | buffer += sprintf( buffer, ")"); |
| 275 | if (arg == OP_IR_IM8_) INC_POS; |
| 276 | break; |
| 277 | |
| 278 | case OP_IM8_: |
| 279 | INC_POS; |
| 280 | case OP_IM8: |
| 281 | buffer += sprintf( buffer, "0x%02x", oprom[POS] ); |
| 282 | INC_POS; |
| 283 | break; |
| 284 | |
| 285 | case OP_IM8I: |
| 286 | buffer += sprintf( buffer, "(0x%02x)", oprom[POS] ); |
| 287 | INC_POS; |
| 288 | break; |
| 289 | |
| 290 | case OP_REGIM8: |
| 291 | buffer += sprintf( buffer, "(%s%s", (op&1) ? "iz": "ix", (oprom[POS]&0x80) ? "-": "+"); |
| 292 | buffer += sprintf( buffer, "%x)", oprom[POS] & 0x1f); |
| 293 | INC_POS; |
| 294 | break; |
| 295 | |
| 296 | case OP_JX_COND: |
| 297 | buffer += sprintf( buffer, "%s", jp_cond[op & 0x07] ); |
| 298 | break; |
| 299 | |
| 300 | |
| 301 | case OP_RMSIM3: |
| 302 | { |
| 303 | UINT8 tmp = oprom[POS]; |
| 304 | INC_POS; |
| 305 | buffer += dasm_im8(buffer, pc, tmp, oprom[POS], oprom, pos); |
| 306 | buffer += sprintf( buffer, ", 0x%02x", ((tmp>>5)&7)+1); |
| 307 | INC_POS; |
| 308 | } |
| 309 | break; |
| 310 | |
| 311 | case OP_IR_IM3: |
| 312 | { |
| 313 | UINT8 tmp = oprom[POS]; |
| 314 | INC_POS; |
| 315 | buffer += sprintf( buffer, "(%s%s", (op&1) ? "iz": "ix", (tmp&0x80) ? "-": "+"); |
| 316 | buffer += dasm_im8(buffer, pc, tmp, oprom[POS], oprom, pos); |
| 317 | buffer += sprintf( buffer, "), 0x%02x", ((oprom[POS]>>5)&7)+1 ); |
| 318 | INC_POS; |
| 319 | } |
| 320 | break; |
| 321 | |
| 322 | case OP_IM3: |
| 323 | buffer += sprintf( buffer, "0x%02x", ((oprom[POS]>>5)&7)+1 ); |
| 324 | INC_POS; |
| 325 | break; |
| 326 | |
| 327 | case OP_MR_SIRI: |
| 328 | buffer += sprintf( buffer, "("); |
| 329 | buffer += dasm_im8(buffer, pc, oprom[POS], oprom, pos, type); |
| 330 | buffer += sprintf( buffer, ")"); |
| 331 | INC_POS; |
| 332 | break; |
| 333 | |
| 334 | case OP_IM7: |
| 335 | { |
| 336 | int tmp = oprom[POS]; |
| 337 | if (tmp&0x80) tmp = 0x80 - tmp; |
| 338 | |
| 339 | buffer += sprintf( buffer, "0x%04x", (pc + tmp) & 0xffff ); |
| 340 | INC_POS; |
| 341 | } |
| 342 | break; |
| 343 | |
| 344 | case OP_IM5: |
| 345 | buffer += sprintf( buffer, "0x%02x", oprom[POS]&0x1f ); |
| 346 | INC_POS; |
| 347 | break; |
| 348 | |
| 349 | case OP_REG16: |
| 350 | case OP_REG16_: |
| 351 | buffer += sprintf( buffer, "%s", reg_16b[(BIT(op,0)<<2) + ((oprom[POS]>>5&3))]); |
| 352 | if (arg == OP_REG16_) INC_POS; |
| 353 | break; |
| 354 | |
| 355 | case OP_IM16: |
| 356 | case OP_IM16A: |
| 357 | { |
| 358 | UINT8 tmp1 = oprom[POS]; |
| 359 | INC_POS; |
| 360 | if (!EXT_ROM && arg == OP_IM16A) INC_POS; |
| 361 | UINT8 tmp2 = oprom[POS]; |
| 362 | buffer += sprintf( buffer, "0x%04x", ((tmp2<<8) | tmp1)); |
| 363 | INC_POS; |
| 364 | } |
| 365 | break; |
| 366 | |
| 367 | case OP_NULL: |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | return buffer - buffer_start; |
| 372 | } |
| 373 | |
| 374 | UINT32 get_dasmflags(UINT8 op) |
| 375 | { |
| 376 | switch (op) |
| 377 | { |
| 378 | case 0x30: case 0x31: case 0x32: case 0x33: //jp |
| 379 | case 0x34: case 0x35: case 0x36: case 0x37: //jp |
| 380 | case 0x70: case 0x71: case 0x72: case 0x73: //cal |
| 381 | case 0x74: case 0x75: case 0x76: case 0x77: //cal |
| 382 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: //jr |
| 383 | case 0xb4: case 0xb5: case 0xb6: case 0xb7: //jr |
| 384 | case 0xde: //jp |
| 385 | case 0xdf: //jp |
| 386 | return DASMFLAG_STEP_OVER; |
| 387 | case 0xf0: case 0xf1: case 0xf2: case 0xf3: //rtn |
| 388 | case 0xf4: case 0xf5: case 0xf6: case 0xf7: //rtn |
| 389 | case 0xfd: //rtni |
| 390 | return DASMFLAG_STEP_OUT; |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | |
| 397 | CPU_DISASSEMBLE( hd61700 ) |
| 398 | { |
| 399 | const hd61700_dasm *inst; |
| 400 | UINT32 dasmflags = 0; |
| 401 | UINT8 op, op1; |
| 402 | int pos = 0, type = EXT_ROM; |
| 403 | |
| 404 | op = oprom[POS]; |
| 405 | INC_POS; |
| 406 | |
| 407 | dasmflags = get_dasmflags(op); |
| 408 | |
| 409 | op1 = oprom[POS]; |
| 410 | |
| 411 | inst = &hd61700_ops[op]; |
| 412 | |
| 413 | buffer += sprintf(buffer,"%-8s", inst->str); |
| 414 | |
| 415 | //dasm first arg |
| 416 | buffer += dasm_arg(buffer, op, pc, inst->arg1, oprom, pos); |
| 417 | |
| 418 | //if present dasm second arg |
| 419 | if (inst->arg2 != OP_NULL) |
| 420 | { |
| 421 | buffer += sprintf(buffer,", "); |
| 422 | buffer += dasm_arg(buffer, op, pc, inst->arg2, oprom, pos); |
| 423 | } |
| 424 | |
| 425 | //if required add the optional jr |
| 426 | if (inst->optjr == true && BIT(op1, 7)) |
| 427 | { |
| 428 | buffer += sprintf( buffer, ", jr "); |
| 429 | buffer += dasm_arg(buffer, op, pc+1, OP_IM7, oprom, pos); |
| 430 | |
| 431 | dasmflags = DASMFLAG_STEP_OVER; |
| 432 | } |
| 433 | |
| 434 | if (pos&1) INC_POS; |
| 435 | |
| 436 | return (pos>>1) | dasmflags | DASMFLAG_SUPPORTED; |
| 437 | } |