src/mess/drivers/pcw.c
| r5420 | r5421 | |
| 121 | 121 | static UINT8 pcw_banks[4]; |
| 122 | 122 | static unsigned char pcw_bank_force = 0; |
| 123 | 123 | |
| 124 | static UINT8 pcw_timer_irq_flag; |
| 125 | static UINT8 pcw_nmi_flag; |
| 124 | 126 | |
| 127 | |
| 128 | |
| 125 | 129 | static void pcw_update_interrupt_counter(void) |
| 126 | 130 | { |
| 127 | 131 | /* never increments past 15! */ |
| r5420 | r5421 | |
| 142 | 146 | NEC765_RDY_PIN_CONNECTED |
| 143 | 147 | }; |
| 144 | 148 | |
| 145 | | /* determines if int line is held or cleared */ |
| 146 | | static void pcw_interrupt_handle(running_machine *machine) |
| 149 | // set/reset INT and NMI lines |
| 150 | static void pcw_update_irqs(running_machine *machine) |
| 147 | 151 | { |
| 148 | | if ( |
| 149 | | (pcw_interrupt_counter!=0) || |
| 150 | | ((fdc_interrupt_code==1) && ((pcw_system_status & (1<<5))!=0)) |
| 151 | | ) |
| 152 | // set NMI line, remains set until FDC interrupt type is changed |
| 153 | if(pcw_nmi_flag != 0) |
| 154 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE); |
| 155 | else |
| 156 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); |
| 157 | |
| 158 | // set IRQ line, timer pulses IRQ line, all other devices hold it as necessary |
| 159 | if(fdc_interrupt_code == 1 && (pcw_system_status & 0x20)) |
| 152 | 160 | { |
| 153 | | if(cpu_get_reg(cputag_get_cpu(machine,"maincpu"),Z80_IFF1)) |
| 154 | | cputag_set_input_line(machine, "maincpu", 0,ASSERT_LINE); |
| 161 | cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE); |
| 162 | return; |
| 155 | 163 | } |
| 156 | | else |
| 164 | |
| 165 | if(pcw_timer_irq_flag != 0) |
| 157 | 166 | { |
| 158 | | cputag_set_input_line(machine, "maincpu", 0,CLEAR_LINE); |
| 167 | cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE); |
| 168 | return; |
| 159 | 169 | } |
| 170 | |
| 171 | cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE); |
| 160 | 172 | } |
| 161 | 173 | |
| 174 | static TIMER_CALLBACK(pcw_timer_pulse) |
| 175 | { |
| 176 | pcw_timer_irq_flag = 0; |
| 177 | pcw_update_irqs(machine); |
| 178 | } |
| 162 | 179 | |
| 163 | | |
| 164 | 180 | /* callback for 1/300ths of a second interrupt */ |
| 165 | 181 | static TIMER_CALLBACK(pcw_timer_interrupt) |
| 166 | 182 | { |
| 167 | 183 | pcw_update_interrupt_counter(); |
| 168 | 184 | |
| 169 | | pcw_interrupt_handle(machine); |
| 185 | pcw_timer_irq_flag = 1; |
| 186 | pcw_update_irqs(machine); |
| 187 | timer_set(machine,ATTOTIME_IN_USEC(2),NULL,0,pcw_timer_pulse); |
| 170 | 188 | } |
| 171 | 189 | |
| 172 | | static int previous_fdc_int_state; |
| 173 | | |
| 174 | | /* set/clear fdc interrupt */ |
| 175 | | static void pcw_trigger_fdc_int(running_machine *machine) |
| 176 | | { |
| 177 | | int state; |
| 178 | | |
| 179 | | state = pcw_system_status & (1<<5); |
| 180 | | |
| 181 | | switch (fdc_interrupt_code) |
| 182 | | { |
| 183 | | /* attach fdc to nmi */ |
| 184 | | case 0: |
| 185 | | { |
| 186 | | /* I'm assuming that the nmi is edge triggered */ |
| 187 | | /* a interrupt from the fdc will cause a change in line state, and |
| 188 | | the nmi will be triggered, but when the state changes because the int |
| 189 | | is cleared this will not cause another nmi */ |
| 190 | | /* I'll emulate it like this to be sure */ |
| 191 | | |
| 192 | | if (state!=previous_fdc_int_state) |
| 193 | | { |
| 194 | | if (state) |
| 195 | | { |
| 196 | | /* Cleared when FDC interrupt mode is set to INT or nothing */ |
| 197 | | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE); |
| 198 | | } |
| 199 | | } |
| 200 | | } |
| 201 | | break; |
| 202 | | |
| 203 | | /* attach fdc to int */ |
| 204 | | case 1: |
| 205 | | { |
| 206 | | pcw_interrupt_handle(machine); |
| 207 | | } |
| 208 | | break; |
| 209 | | |
| 210 | | /* do not interrupt */ |
| 211 | | default: |
| 212 | | break; |
| 213 | | } |
| 214 | | |
| 215 | | previous_fdc_int_state = state; |
| 216 | | } |
| 217 | | |
| 218 | 190 | /* fdc interrupt callback. set/clear fdc int */ |
| 219 | 191 | static NEC765_INTERRUPT( pcw_fdc_interrupt ) |
| 220 | 192 | { |
| 221 | | |
| 222 | 193 | if (state == CLEAR_LINE) |
| 223 | 194 | pcw_system_status &= ~(1<<5); |
| 224 | 195 | else |
| 196 | { |
| 225 | 197 | pcw_system_status |= (1<<5); |
| 226 | | |
| 227 | | pcw_trigger_fdc_int(device->machine); |
| 198 | if(fdc_interrupt_code == 0) // NMI is held until interrupt type is changed |
| 199 | pcw_nmi_flag = 1; |
| 200 | } |
| 228 | 201 | } |
| 229 | 202 | |
| 230 | 203 | |
| r5420 | r5421 | |
| 270 | 243 | memory_install_read8_handler(space, |
| 271 | 244 | block * 0x04000 + 0x3ff0, block * 0x04000 + 0x3fff, 0, 0, |
| 272 | 245 | pcw_keyboard_r); |
| 273 | | LOG(("MEM: read block %i -> bank %i\n",block,bank)); |
| 246 | // LOG(("MEM: read block %i -> bank %i\n",block,bank)); |
| 274 | 247 | } |
| 275 | 248 | else |
| 276 | 249 | { |
| r5420 | r5421 | |
| 278 | 251 | memory_install_read8_handler(space, |
| 279 | 252 | block * 0x04000 + 0x0000, block * 0x04000 + 0x3fff, 0, 0, |
| 280 | 253 | (read8_space_func) (STATIC_BANK1 + (FPTR)block)); |
| 281 | | LOG(("MEM: read block %i -> bank %i\n",block,bank)); |
| 254 | // LOG(("MEM: read block %i -> bank %i\n",block,bank)); |
| 282 | 255 | } |
| 283 | 256 | memory_set_bankptr(machine, block + 1, mess_ram + ((bank * 0x4000) % mess_ram_size)); |
| 284 | 257 | } |
| r5420 | r5421 | |
| 288 | 261 | static void pcw_update_write_memory_block(running_machine *machine, int block, int bank) |
| 289 | 262 | { |
| 290 | 263 | memory_set_bankptr(machine, block + 5, mess_ram + ((bank * 0x4000) % mess_ram_size)); |
| 291 | | LOG(("MEM: write block %i -> bank %i\n",block,bank)); |
| 264 | // LOG(("MEM: write block %i -> bank %i\n",block,bank)); |
| 292 | 265 | } |
| 293 | 266 | |
| 294 | 267 | |
| r5420 | r5421 | |
| 388 | 361 | data = pcw_get_sys_status(space->machine); |
| 389 | 362 | /* clear int counter */ |
| 390 | 363 | pcw_interrupt_counter = 0; |
| 391 | | /* update interrupt */ |
| 392 | | pcw_interrupt_handle(space->machine); |
| 393 | 364 | /* return data */ |
| 394 | 365 | LOG(("SYS: IRQ counter read, returning %02x\n",data)); |
| 395 | 366 | return data; |
| r5420 | r5421 | |
| 474 | 445 | { |
| 475 | 446 | /* yes */ |
| 476 | 447 | |
| 477 | | pcw_interrupt_handle(space->machine); |
| 448 | pcw_update_irqs(space->machine); |
| 478 | 449 | } |
| 479 | 450 | |
| 480 | | pcw_trigger_fdc_int(space->machine); |
| 481 | 451 | } |
| 482 | 452 | break; |
| 483 | 453 | |
| r5420 | r5421 | |
| 496 | 466 | /* yes */ |
| 497 | 467 | |
| 498 | 468 | /* clear nmi interrupt */ |
| 499 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); |
| 469 | pcw_nmi_flag = 0; |
| 500 | 470 | } |
| 501 | 471 | |
| 502 | 472 | /* re-issue interrupt */ |
| 503 | | pcw_interrupt_handle(space->machine); |
| 473 | pcw_update_irqs(space->machine); |
| 504 | 474 | } |
| 505 | 475 | break; |
| 506 | 476 | |
| r5420 | r5421 | |
| 513 | 483 | fdc_interrupt_code = 2; |
| 514 | 484 | |
| 515 | 485 | /* previously connected to NMI or INT? */ |
| 516 | | if ((fdc_previous_interrupt_code == 0)) |
| 486 | if ((fdc_previous_interrupt_code == 0) || (fdc_previous_interrupt_code == 1)) |
| 517 | 487 | { |
| 518 | 488 | /* yes */ |
| 519 | 489 | |
| 520 | 490 | /* Clear NMI */ |
| 521 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); |
| 522 | | |
| 491 | pcw_nmi_flag = 0; |
| 523 | 492 | } |
| 524 | | pcw_interrupt_handle(space->machine); |
| 493 | pcw_update_irqs(space->machine); |
| 525 | 494 | |
| 526 | 495 | } |
| 527 | 496 | break; |
| r5420 | r5421 | |
| 657 | 626 | static WRITE8_HANDLER(pcw_expansion_w) |
| 658 | 627 | { |
| 659 | 628 | logerror("pcw expansion w: %04x %02x\n",offset+0x080, data); |
| 660 | | |
| 661 | | |
| 662 | | |
| 663 | | |
| 664 | | |
| 665 | | |
| 666 | 629 | } |
| 667 | 630 | |
| 668 | 631 | static READ8_HANDLER(pcw_fdc_r) |