src/mess/machine/at.c
| r5959 | r5960 | |
| 36 | 36 | #define LOG_PORT80 0 |
| 37 | 37 | #define LOG_KBDC 0 |
| 38 | 38 | |
| 39 | | static struct { |
| 40 | | const device_config *maincpu; |
| 41 | | const device_config *pic8259_master; |
| 42 | | const device_config *pic8259_slave; |
| 43 | | const device_config *dma8237_1; |
| 44 | | const device_config *dma8237_2; |
| 45 | | const device_config *pit8254; |
| 46 | | } at_devices; |
| 47 | | |
| 48 | 39 | static const SOUNDBLASTER_CONFIG soundblaster = { 1,5, {1,0} }; |
| 49 | 40 | |
| 50 | 41 | |
| r5959 | r5960 | |
| 60 | 51 | |
| 61 | 52 | |
| 62 | 53 | static PIC8259_SET_INT_LINE( at_pic8259_slave_set_int_line ) { |
| 63 | | pic8259_set_irq_line( at_devices.pic8259_master, 2, interrupt); |
| 54 | at_state *st = device->machine->driver_data; |
| 55 | pic8259_set_irq_line( st->pic8259_master, 2, interrupt); |
| 64 | 56 | } |
| 65 | 57 | |
| 66 | 58 | |
| r5959 | r5960 | |
| 115 | 107 | |
| 116 | 108 | static PIT8253_OUTPUT_CHANGED( at_pit8254_out0_changed ) |
| 117 | 109 | { |
| 118 | | if ( at_devices.pic8259_master ) { |
| 119 | | pic8259_set_irq_line(at_devices.pic8259_master, 0, state); |
| 110 | at_state *st = device->machine->driver_data; |
| 111 | if ( st->pic8259_master ) { |
| 112 | pic8259_set_irq_line(st->pic8259_master, 0, state); |
| 120 | 113 | } |
| 121 | 114 | } |
| 122 | 115 | |
| r5959 | r5960 | |
| 151 | 144 | } |
| 152 | 145 | |
| 153 | 146 | |
| 154 | | static void at_set_irq_line(int irq, int state) { |
| 155 | | pic8259_set_irq_line(at_devices.pic8259_master, irq, state); |
| 147 | static void at_set_irq_line(running_machine *machine,int irq, int state) { |
| 148 | at_state *st = machine->driver_data; |
| 149 | pic8259_set_irq_line(st->pic8259_master, irq, state); |
| 156 | 150 | } |
| 157 | 151 | |
| 158 | 152 | |
| 159 | 153 | static void at_set_keyb_int(running_machine *machine, int state) { |
| 160 | | pic8259_set_irq_line(at_devices.pic8259_master, 1, state); |
| 154 | at_state *st = machine->driver_data; |
| 155 | pic8259_set_irq_line(st->pic8259_master, 1, state); |
| 161 | 156 | } |
| 162 | 157 | |
| 163 | 158 | |
| r5959 | r5960 | |
| 182 | 177 | |
| 183 | 178 | static void at_keyboard_interrupt(running_machine *machine, int state) |
| 184 | 179 | { |
| 185 | | pic8259_set_irq_line(at_devices.pic8259_master, 1, state); |
| 180 | at_state *st = machine->driver_data; |
| 181 | pic8259_set_irq_line(st->pic8259_master, 1, state); |
| 186 | 182 | } |
| 187 | 183 | |
| 188 | 184 | |
| r5959 | r5960 | |
| 248 | 244 | |
| 249 | 245 | static DMA8237_HRQ_CHANGED( pc_dma_hrq_changed ) |
| 250 | 246 | { |
| 251 | | cpu_set_input_line(at_devices.maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE); |
| 247 | at_state *st = device->machine->driver_data; |
| 248 | cpu_set_input_line(st->maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE); |
| 252 | 249 | |
| 253 | 250 | /* Assert HLDA */ |
| 254 | 251 | dma8237_set_hlda( device, state ); |
| r5959 | r5960 | |
| 337 | 334 | /* called when a interrupt is set/cleared from com hardware */ |
| 338 | 335 | static INS8250_INTERRUPT( at_com_interrupt_1 ) |
| 339 | 336 | { |
| 340 | | pic8259_set_irq_line(at_devices.pic8259_master, 4, state); |
| 337 | at_state *st = device->machine->driver_data; |
| 338 | pic8259_set_irq_line(st->pic8259_master, 4, state); |
| 341 | 339 | } |
| 342 | 340 | |
| 343 | 341 | static INS8250_INTERRUPT( at_com_interrupt_2 ) |
| 344 | 342 | { |
| 345 | | pic8259_set_irq_line(at_devices.pic8259_master, 3, state); |
| 343 | at_state *st = device->machine->driver_data; |
| 344 | pic8259_set_irq_line(st->pic8259_master, 3, state); |
| 346 | 345 | } |
| 347 | 346 | |
| 348 | 347 | /* called when com registers read/written - used to update peripherals that |
| r5959 | r5960 | |
| 404 | 403 | |
| 405 | 404 | static void at_fdc_interrupt(running_machine *machine, int state) |
| 406 | 405 | { |
| 407 | | pic8259_set_irq_line(at_devices.pic8259_master, 6, state); |
| 406 | at_state *st = machine->driver_data; |
| 407 | pic8259_set_irq_line(st->pic8259_master, 6, state); |
| 408 | 408 | //if ( mess_ram[0x0490] == 0x74 ) |
| 409 | 409 | // mess_ram[0x0490] = 0x54; |
| 410 | 410 | } |
| r5959 | r5960 | |
| 412 | 412 | |
| 413 | 413 | static void at_fdc_dma_drq(running_machine *machine, int state, int read_) |
| 414 | 414 | { |
| 415 | | dma8237_drq_write( at_devices.dma8237_1, FDC_DMA, state); |
| 415 | at_state *st = machine->driver_data; |
| 416 | dma8237_drq_write( st->dma8237_1, FDC_DMA, state); |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | 419 | static const device_config *at_get_device(running_machine *machine) |
| r5959 | r5960 | |
| 430 | 431 | |
| 431 | 432 | |
| 432 | 433 | static int at_get_out2(running_machine *machine) { |
| 433 | | return pit8253_get_output(at_devices.pit8254, 2 ); |
| 434 | at_state *st = machine->driver_data; |
| 435 | return pit8253_get_output(st->pit8254, 2 ); |
| 434 | 436 | } |
| 435 | 437 | |
| 436 | 438 | |
| r5959 | r5960 | |
| 494 | 496 | |
| 495 | 497 | static WRITE8_HANDLER( at_kbdc8042_p2_w ) |
| 496 | 498 | { |
| 499 | at_state *st = space->machine->driver_data; |
| 500 | |
| 497 | 501 | logerror("%04x: writing $%02x to P2\n", cpu_get_pc(cputag_get_cpu(space->machine, "maincpu")), data ); |
| 498 | 502 | |
| 499 | 503 | at_set_gate_a20( space->machine, ( data & 0x02 ) ? 1 : 0 ); |
| r5959 | r5960 | |
| 501 | 505 | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, ( data & 0x01 ) ? CLEAR_LINE : ASSERT_LINE ); |
| 502 | 506 | |
| 503 | 507 | /* OPT BUF FULL is connected to IR1 on the master 8259 */ |
| 504 | | if ( at_devices.pic8259_master ) |
| 505 | | pic8259_set_irq_line(at_devices.pic8259_master, 1, ( data & 0x10 ) ? ASSERT_LINE : CLEAR_LINE ); |
| 508 | if ( st->pic8259_master ) |
| 509 | pic8259_set_irq_line(st->pic8259_master, 1, ( data & 0x10 ) ? ASSERT_LINE : CLEAR_LINE ); |
| 506 | 510 | |
| 507 | 511 | at_kbdc8042.clock_signal = ( data & 0x40 ) ? 1 : 0; |
| 508 | 512 | at_kbdc8042.data_signal = ( data & 0x80 ) ? 1 : 0; |
| r5959 | r5960 | |
| 562 | 566 | { |
| 563 | 567 | static int poll_delay = 4; |
| 564 | 568 | UINT8 data = 0; |
| 565 | | |
| 569 | at_state *st = space->machine->driver_data; |
| 570 | |
| 566 | 571 | switch ( offset ) |
| 567 | 572 | { |
| 568 | 573 | case 0: /* A2 is wired to 8042 A0 */ |
| r5959 | r5960 | |
| 581 | 586 | } |
| 582 | 587 | data = (data & ~0x10) | ( at_kbdc8042.offset1 & 0x10 ); |
| 583 | 588 | |
| 584 | | if ( pit8253_get_output(at_devices.pit8254, 2 ) ) |
| 589 | if ( pit8253_get_output(st->pit8254, 2 ) ) |
| 585 | 590 | data |= 0x20; |
| 586 | 591 | else |
| 587 | 592 | data &= ~0x20; /* ps2m30 wants this */ |
| r5959 | r5960 | |
| 607 | 612 | |
| 608 | 613 | WRITE8_HANDLER(at_kbdc8042_w) |
| 609 | 614 | { |
| 615 | at_state *st = space->machine->driver_data; |
| 610 | 616 | if (LOG_KBDC) |
| 611 | 617 | logerror("kbdc8042_8_w(): ofset=%d data=0x%02x\n", offset, data); |
| 612 | 618 | |
| r5959 | r5960 | |
| 617 | 623 | |
| 618 | 624 | case 1: |
| 619 | 625 | at_kbdc8042.speaker = data; |
| 620 | | pit8253_gate_w( at_devices.pit8254, 2, data & 1); |
| 626 | pit8253_gate_w( st->pit8254, 2, data & 1); |
| 621 | 627 | at_speaker_set_spkrdata( space->machine, data & 0x02 ); |
| 622 | 628 | break; |
| 623 | 629 | |
| r5959 | r5960 | |
| 769 | 775 | |
| 770 | 776 | static IRQ_CALLBACK(at_irq_callback) |
| 771 | 777 | { |
| 772 | | return pic8259_acknowledge( at_devices.pic8259_master); |
| 778 | at_state *st = device->machine->driver_data; |
| 779 | return pic8259_acknowledge( st->pic8259_master); |
| 773 | 780 | } |
| 774 | 781 | |
| 775 | 782 | |
| r5959 | r5960 | |
| 784 | 791 | |
| 785 | 792 | MACHINE_RESET( at ) |
| 786 | 793 | { |
| 787 | | at_devices.maincpu = devtag_get_device(machine, "maincpu"); |
| 788 | | at_devices.pic8259_master = devtag_get_device(machine, "pic8259_master"); |
| 789 | | at_devices.pic8259_slave = devtag_get_device(machine, "pic8259_slave"); |
| 790 | | at_devices.dma8237_1 = devtag_get_device(machine, "dma8237_1"); |
| 791 | | at_devices.dma8237_2 = devtag_get_device(machine, "dma8237_2"); |
| 792 | | at_devices.pit8254 = devtag_get_device(machine, "pit8254"); |
| 794 | at_state *st = machine->driver_data; |
| 795 | st->maincpu = devtag_get_device(machine, "maincpu"); |
| 796 | st->pic8259_master = devtag_get_device(machine, "pic8259_master"); |
| 797 | st->pic8259_slave = devtag_get_device(machine, "pic8259_slave"); |
| 798 | st->dma8237_1 = devtag_get_device(machine, "dma8237_1"); |
| 799 | st->dma8237_2 = devtag_get_device(machine, "dma8237_2"); |
| 800 | st->pit8254 = devtag_get_device(machine, "pit8254"); |
| 793 | 801 | pc_mouse_set_serial_port( devtag_get_device(machine, "ns16450_0") ); |
| 794 | 802 | } |
| 795 | 803 | |
src/mess/machine/pc.c
| r5959 | r5960 | |
| 58 | 58 | } \ |
| 59 | 59 | } while (0) |
| 60 | 60 | |
| 61 | | static struct { |
| 62 | | const device_config *maincpu; |
| 63 | | const device_config *pic8259; |
| 64 | | const device_config *dma8237; |
| 65 | | const device_config *pit8253; |
| 66 | | /* U73 is an LS74 - dual flip flop */ |
| 67 | | /* Q2 is set by OUT1 from the 8253 and goes to DRQ1 on the 8237 */ |
| 68 | | UINT8 u73_q2; |
| 69 | | UINT8 out1; |
| 70 | | } pc_devices; |
| 71 | | |
| 72 | 61 | /************************************************************************* |
| 73 | 62 | * |
| 74 | 63 | * PC DMA stuff |
| 75 | 64 | * |
| 76 | 65 | *************************************************************************/ |
| 77 | 66 | |
| 78 | | static UINT8 dma_offset[2][4]; |
| 79 | | |
| 80 | | |
| 81 | 67 | READ8_HANDLER(pc_page_r) |
| 82 | 68 | { |
| 83 | 69 | return 0xFF; |
| r5959 | r5960 | |
| 86 | 72 | |
| 87 | 73 | WRITE8_HANDLER(pc_page_w) |
| 88 | 74 | { |
| 75 | pc_state *st = space->machine->driver_data; |
| 89 | 76 | switch(offset % 4) |
| 90 | 77 | { |
| 91 | 78 | case 1: |
| 92 | | dma_offset[0][2] = data; |
| 79 | st->dma_offset[0][2] = data; |
| 93 | 80 | break; |
| 94 | 81 | case 2: |
| 95 | | dma_offset[0][3] = data; |
| 82 | st->dma_offset[0][3] = data; |
| 96 | 83 | break; |
| 97 | 84 | case 3: |
| 98 | | dma_offset[0][0] = dma_offset[0][1] = data; |
| 85 | st->dma_offset[0][0] = st->dma_offset[0][1] = data; |
| 99 | 86 | break; |
| 100 | 87 | } |
| 101 | 88 | } |
| r5959 | r5960 | |
| 103 | 90 | |
| 104 | 91 | static DMA8237_HRQ_CHANGED( pc_dma_hrq_changed ) |
| 105 | 92 | { |
| 106 | | cpu_set_input_line(pc_devices.maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE); |
| 93 | pc_state *st = device->machine->driver_data; |
| 94 | cpu_set_input_line(st->maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE); |
| 107 | 95 | |
| 108 | 96 | /* Assert HLDA */ |
| 109 | 97 | dma8237_set_hlda( device, state ); |
| r5959 | r5960 | |
| 113 | 101 | static DMA8237_MEM_READ( pc_dma_read_byte ) |
| 114 | 102 | { |
| 115 | 103 | UINT8 result; |
| 116 | | offs_t page_offset = (((offs_t) dma_offset[0][channel]) << 16) |
| 104 | pc_state *st = device->machine->driver_data; |
| 105 | offs_t page_offset = (((offs_t) st->dma_offset[0][channel]) << 16) |
| 117 | 106 | & 0x0F0000; |
| 118 | 107 | |
| 119 | 108 | result = memory_read_byte( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), page_offset + offset); |
| r5959 | r5960 | |
| 123 | 112 | |
| 124 | 113 | static DMA8237_MEM_WRITE( pc_dma_write_byte ) |
| 125 | 114 | { |
| 126 | | offs_t page_offset = (((offs_t) dma_offset[0][channel]) << 16) |
| 115 | pc_state *st = device->machine->driver_data; |
| 116 | offs_t page_offset = (((offs_t) st->dma_offset[0][channel]) << 16) |
| 127 | 117 | & 0x0F0000; |
| 128 | 118 | |
| 129 | 119 | memory_write_byte( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), page_offset + offset, data); |
| r5959 | r5960 | |
| 156 | 146 | |
| 157 | 147 | static DMA8237_CHANNEL_WRITE( pc_dma8237_0_dack_w ) |
| 158 | 148 | { |
| 159 | | pc_devices.u73_q2 = 0; |
| 160 | | dma8237_drq_write( pc_devices.dma8237, 0, pc_devices.u73_q2 ); |
| 149 | pc_state *st = device->machine->driver_data; |
| 150 | st->u73_q2 = 0; |
| 151 | dma8237_drq_write( st->dma8237, 0, st->u73_q2 ); |
| 161 | 152 | } |
| 162 | 153 | |
| 163 | 154 | |
| r5959 | r5960 | |
| 247 | 238 | * PC Speaker related |
| 248 | 239 | * |
| 249 | 240 | *************************************************************************/ |
| 250 | | |
| 251 | | static UINT8 pc_spkrdata = 0; |
| 252 | | static UINT8 pc_input = 0; |
| 253 | | |
| 254 | | UINT8 pc_speaker_get_spk(void) |
| 241 | UINT8 pc_speaker_get_spk(running_machine *machine) |
| 255 | 242 | { |
| 256 | | return pc_spkrdata & pc_input; |
| 243 | pc_state *st = machine->driver_data; |
| 244 | return st->pc_spkrdata & st->pc_input; |
| 257 | 245 | } |
| 258 | 246 | |
| 259 | 247 | |
| 260 | 248 | void pc_speaker_set_spkrdata(running_machine *machine, UINT8 data) |
| 261 | 249 | { |
| 262 | 250 | const device_config *speaker = devtag_get_device(machine, "speaker"); |
| 263 | | pc_spkrdata = data ? 1 : 0; |
| 264 | | speaker_level_w( speaker, pc_speaker_get_spk() ); |
| 251 | pc_state *st = machine->driver_data; |
| 252 | st->pc_spkrdata = data ? 1 : 0; |
| 253 | speaker_level_w( speaker, pc_speaker_get_spk(machine) ); |
| 265 | 254 | } |
| 266 | 255 | |
| 267 | 256 | |
| 268 | 257 | void pc_speaker_set_input(running_machine *machine, UINT8 data) |
| 269 | 258 | { |
| 270 | 259 | const device_config *speaker = devtag_get_device(machine, "speaker"); |
| 271 | | pc_input = data ? 1 : 0; |
| 272 | | speaker_level_w( speaker, pc_speaker_get_spk() ); |
| 260 | pc_state *st = machine->driver_data; |
| 261 | st->pc_input = data ? 1 : 0; |
| 262 | speaker_level_w( speaker, pc_speaker_get_spk(machine) ); |
| 273 | 263 | } |
| 274 | 264 | |
| 275 | 265 | |
| r5959 | r5960 | |
| 281 | 271 | |
| 282 | 272 | static PIT8253_OUTPUT_CHANGED( ibm5150_pit8253_out0_changed ) |
| 283 | 273 | { |
| 284 | | pic8259_set_irq_line(pc_devices.pic8259, 0, state); |
| 274 | pc_state *st = device->machine->driver_data; |
| 275 | pic8259_set_irq_line(st->pic8259, 0, state); |
| 285 | 276 | } |
| 286 | 277 | |
| 287 | 278 | |
| 288 | 279 | static PIT8253_OUTPUT_CHANGED( ibm5150_pit8253_out1_changed ) |
| 289 | 280 | { |
| 281 | pc_state *st = device->machine->driver_data; |
| 290 | 282 | /* Trigger DMA channel #0 */ |
| 291 | | if ( pc_devices.out1 == 0 && state == 1 && pc_devices.u73_q2 == 0 ) |
| 283 | if ( st->out1 == 0 && state == 1 && st->u73_q2 == 0 ) |
| 292 | 284 | { |
| 293 | | pc_devices.u73_q2 = 1; |
| 294 | | dma8237_drq_write( pc_devices.dma8237, 0, pc_devices.u73_q2 ); |
| 285 | st->u73_q2 = 1; |
| 286 | dma8237_drq_write( st->dma8237, 0, st->u73_q2 ); |
| 295 | 287 | } |
| 296 | | pc_devices.out1 = state; |
| 288 | st->out1 = state; |
| 297 | 289 | } |
| 298 | 290 | |
| 299 | 291 | |
| r5959 | r5960 | |
| 351 | 343 | /* called when a interrupt is set/cleared from com hardware */ |
| 352 | 344 | static INS8250_INTERRUPT( pc_com_interrupt_1 ) |
| 353 | 345 | { |
| 354 | | pic8259_set_irq_line(pc_devices.pic8259, 4, state); |
| 346 | pc_state *st = device->machine->driver_data; |
| 347 | pic8259_set_irq_line(st->pic8259, 4, state); |
| 355 | 348 | } |
| 356 | 349 | |
| 357 | 350 | static INS8250_INTERRUPT( pc_com_interrupt_2 ) |
| 358 | 351 | { |
| 359 | | pic8259_set_irq_line(pc_devices.pic8259, 3, state); |
| 352 | pc_state *st = device->machine->driver_data; |
| 353 | pic8259_set_irq_line(st->pic8259, 3, state); |
| 360 | 354 | } |
| 361 | 355 | |
| 362 | 356 | /* called when com registers read/written - used to update peripherals that |
| r5959 | r5960 | |
| 493 | 487 | |
| 494 | 488 | static void pcjr_set_keyb_int(running_machine *machine, int state) |
| 495 | 489 | { |
| 490 | pc_state *st = machine->driver_data; |
| 496 | 491 | if ( state ) |
| 497 | 492 | { |
| 498 | 493 | UINT8 data = pc_keyb_read(); |
| r5959 | r5960 | |
| 530 | 525 | pcjr_keyb.latch = 1; |
| 531 | 526 | if ( nmi_enabled & 0x80 ) |
| 532 | 527 | { |
| 533 | | cpu_set_input_line( pc_devices.pit8253->machine->firstcpu, INPUT_LINE_NMI, PULSE_LINE ); |
| 528 | cpu_set_input_line( st->pit8253->machine->firstcpu, INPUT_LINE_NMI, PULSE_LINE ); |
| 534 | 529 | } |
| 535 | 530 | } |
| 536 | 531 | } |
| r5959 | r5960 | |
| 605 | 600 | * |
| 606 | 601 | **********************************************************/ |
| 607 | 602 | |
| 608 | | static struct { |
| 609 | | int portc_switch_high; |
| 610 | | int speaker; |
| 611 | | int keyboard_clear; |
| 612 | | UINT8 keyb_clock; |
| 613 | | UINT8 portb; |
| 614 | | UINT8 clock_signal; |
| 615 | | UINT8 data_signal; |
| 616 | | UINT8 shift_register; |
| 617 | | UINT8 shift_enable; |
| 618 | | write8_space_func clock_callback; |
| 619 | | write8_space_func data_callback; |
| 620 | | } pc_ppi={ 0 }; |
| 621 | | |
| 622 | | |
| 623 | 603 | static READ8_DEVICE_HANDLER (ibm5150_ppi_porta_r) |
| 624 | 604 | { |
| 625 | 605 | int data = 0xFF; |
| 626 | 606 | running_machine *machine = device->machine; |
| 627 | | |
| 607 | pc_state *st = device->machine->driver_data; |
| 608 | |
| 628 | 609 | /* KB port A */ |
| 629 | | if (pc_ppi.keyboard_clear) |
| 610 | if (st->ppi_keyboard_clear) |
| 630 | 611 | { |
| 631 | 612 | /* 0 0 - no floppy drives |
| 632 | 613 | * 1 Not used |
| r5959 | r5960 | |
| 656 | 637 | } |
| 657 | 638 | else |
| 658 | 639 | { |
| 659 | | data = pc_ppi.shift_register; |
| 640 | data = st->ppi_shift_register; |
| 660 | 641 | } |
| 661 | 642 | PIO_LOG(1,"PIO_A_r",("$%02x\n", data)); |
| 662 | 643 | return data; |
| r5959 | r5960 | |
| 676 | 657 | |
| 677 | 658 | static READ8_DEVICE_HANDLER ( ibm5150_ppi_portc_r ) |
| 678 | 659 | { |
| 679 | | int timer2_output = pit8253_get_output( pc_devices.pit8253, 2 ); |
| 660 | pc_state *st = device->machine->driver_data; |
| 661 | int timer2_output = pit8253_get_output( st->pit8253, 2 ); |
| 680 | 662 | int data=0xff; |
| 681 | 663 | running_machine *machine = device->machine; |
| 682 | 664 | |
| 683 | 665 | data&=~0x80; // no parity error |
| 684 | 666 | data&=~0x40; // no error on expansion board |
| 685 | 667 | /* KB port C: equipment flags */ |
| 686 | | if (pc_ppi.portc_switch_high) |
| 668 | if (st->ppi_portc_switch_high) |
| 687 | 669 | { |
| 688 | 670 | /* read hi nibble of SW2 */ |
| 689 | 671 | data = data & 0xf0; |
| r5959 | r5960 | |
| 718 | 700 | PIO_LOG(1,"PIO_C_r (lo)",("$%02x\n", data)); |
| 719 | 701 | } |
| 720 | 702 | |
| 721 | | if ( ! ( pc_ppi.portb & 0x08 ) ) |
| 703 | if ( ! ( st->ppi_portb & 0x08 ) ) |
| 722 | 704 | { |
| 723 | 705 | double tap_val = cassette_input( devtag_get_device(device->machine, "cassette") ); |
| 724 | 706 | |
| r5959 | r5960 | |
| 733 | 715 | } |
| 734 | 716 | else |
| 735 | 717 | { |
| 736 | | if ( pc_ppi.portb & 0x01 ) |
| 718 | if ( st->ppi_portb & 0x01 ) |
| 737 | 719 | { |
| 738 | 720 | data = ( data & ~0x10 ) | ( timer2_output ? 0x10 : 0x00 ); |
| 739 | 721 | } |
| r5959 | r5960 | |
| 755 | 737 | |
| 756 | 738 | static WRITE8_DEVICE_HANDLER ( ibm5150_ppi_portb_w ) |
| 757 | 739 | { |
| 740 | pc_state *st = device->machine->driver_data; |
| 758 | 741 | /* KB controller port B */ |
| 759 | | pc_ppi.portb = data; |
| 760 | | pc_ppi.portc_switch_high = data & 0x08; |
| 761 | | pc_ppi.keyboard_clear = data & 0x80; |
| 762 | | pc_ppi.keyb_clock = data & 0x40; |
| 763 | | pit8253_gate_w( pc_devices.pit8253, 2, data & 1); |
| 742 | st->ppi_portb = data; |
| 743 | st->ppi_portc_switch_high = data & 0x08; |
| 744 | st->ppi_keyboard_clear = data & 0x80; |
| 745 | st->ppi_keyb_clock = data & 0x40; |
| 746 | pit8253_gate_w( st->pit8253, 2, data & 1); |
| 764 | 747 | pc_speaker_set_spkrdata( device->machine, data & 0x02 ); |
| 765 | 748 | |
| 766 | 749 | cassette_change_state( devtag_get_device(device->machine, "cassette"), ( data & 0x08 ) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR); |
| 767 | 750 | |
| 768 | | pc_ppi.clock_signal = ( pc_ppi.keyb_clock ) ? 1 : 0; |
| 751 | st->ppi_clock_signal = ( st->ppi_keyb_clock ) ? 1 : 0; |
| 769 | 752 | |
| 770 | | pc_ppi.clock_callback( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), 0, pc_ppi.clock_signal ); |
| 753 | st->ppi_clock_callback( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), 0, st->ppi_clock_signal ); |
| 771 | 754 | |
| 772 | 755 | /* If PB7 is set clear the shift register and reset the IRQ line */ |
| 773 | | if ( pc_ppi.keyboard_clear ) |
| 756 | if ( st->ppi_keyboard_clear ) |
| 774 | 757 | { |
| 775 | | pic8259_set_irq_line(pc_devices.pic8259, 1, 0); |
| 776 | | pc_ppi.shift_register = 0; |
| 777 | | pc_ppi.shift_enable = 1; |
| 758 | pic8259_set_irq_line(st->pic8259, 1, 0); |
| 759 | st->ppi_shift_register = 0; |
| 760 | st->ppi_shift_enable = 1; |
| 778 | 761 | } |
| 779 | 762 | } |
| 780 | 763 | |
| r5959 | r5960 | |
| 790 | 773 | |
| 791 | 774 | static WRITE8_HANDLER( ibm5150_kb_set_clock_signal ) |
| 792 | 775 | { |
| 793 | | if ( pc_ppi.clock_signal != data ) |
| 776 | pc_state *st = space->machine->driver_data; |
| 777 | if ( st->ppi_clock_signal != data ) |
| 794 | 778 | { |
| 795 | | if ( pc_ppi.keyb_clock && pc_ppi.shift_enable ) |
| 779 | if ( st->ppi_keyb_clock && st->ppi_shift_enable ) |
| 796 | 780 | { |
| 797 | | pc_ppi.clock_signal = data; |
| 798 | | if ( ! pc_ppi.keyboard_clear ) |
| 781 | st->ppi_clock_signal = data; |
| 782 | if ( ! st->ppi_keyboard_clear ) |
| 799 | 783 | { |
| 800 | 784 | /* Data is clocked in on a high->low transition */ |
| 801 | 785 | if ( ! data ) |
| 802 | 786 | { |
| 803 | | UINT8 trigger_irq = pc_ppi.shift_register & 0x01; |
| 787 | UINT8 trigger_irq = st->ppi_shift_register & 0x01; |
| 804 | 788 | |
| 805 | | pc_ppi.shift_register = ( pc_ppi.shift_register >> 1 ) | ( pc_ppi.data_signal << 7 ); |
| 789 | st->ppi_shift_register = ( st->ppi_shift_register >> 1 ) | ( st->ppi_data_signal << 7 ); |
| 806 | 790 | if ( trigger_irq ) |
| 807 | 791 | { |
| 808 | | pic8259_set_irq_line(pc_devices.pic8259, 1, 1); |
| 809 | | pc_ppi.shift_enable = 0; |
| 810 | | pc_ppi.clock_signal = 0; |
| 811 | | pc_ppi.clock_callback( space, 0, 0 ); |
| 792 | pic8259_set_irq_line(st->pic8259, 1, 1); |
| 793 | st->ppi_shift_enable = 0; |
| 794 | st->ppi_clock_signal = 0; |
| 795 | st->ppi_clock_callback( space, 0, 0 ); |
| 812 | 796 | } |
| 813 | 797 | } |
| 814 | 798 | } |
| 815 | 799 | } |
| 816 | 800 | } |
| 817 | 801 | |
| 818 | | pc_ppi.clock_callback( space, 0, pc_ppi.clock_signal ); |
| 802 | st->ppi_clock_callback( space, 0, st->ppi_clock_signal ); |
| 819 | 803 | } |
| 820 | 804 | |
| 821 | 805 | |
| 822 | 806 | static WRITE8_HANDLER( ibm5150_kb_set_data_signal ) |
| 823 | 807 | { |
| 824 | | pc_ppi.data_signal = data; |
| 808 | pc_state *st = space->machine->driver_data; |
| 809 | |
| 810 | st->ppi_data_signal = data; |
| 825 | 811 | |
| 826 | | pc_ppi.data_callback( space, 0, pc_ppi.data_signal ); |
| 812 | st->ppi_data_callback( space, 0, st->ppi_data_signal ); |
| 827 | 813 | } |
| 828 | 814 | |
| 829 | 815 | |
| 830 | 816 | static void ibm5150_set_keyboard_interface( running_machine *machine, write8_space_func clock_cb, write8_space_func data_cb ) |
| 831 | 817 | { |
| 832 | | pc_ppi.clock_callback = clock_cb; |
| 833 | | pc_ppi.data_callback = data_cb; |
| 818 | pc_state *st = machine->driver_data; |
| 819 | |
| 820 | st->ppi_clock_callback = clock_cb; |
| 821 | st->ppi_data_callback = data_cb; |
| 834 | 822 | } |
| 835 | 823 | |
| 836 | 824 | |
| r5959 | r5960 | |
| 851 | 839 | { |
| 852 | 840 | int data = 0xFF; |
| 853 | 841 | running_machine *machine = device->machine; |
| 854 | | |
| 842 | pc_state *st = device->machine->driver_data; |
| 843 | |
| 855 | 844 | /* KB port A */ |
| 856 | | if (pc_ppi.keyboard_clear) |
| 845 | if (st->ppi_keyboard_clear) |
| 857 | 846 | { |
| 858 | 847 | /* 0 0 - no floppy drives |
| 859 | 848 | * 1 Not used |
| r5959 | r5960 | |
| 868 | 857 | } |
| 869 | 858 | else |
| 870 | 859 | { |
| 871 | | data = pc_ppi.shift_register; |
| 860 | data = st->ppi_shift_register; |
| 872 | 861 | } |
| 873 | 862 | PIO_LOG(1,"PIO_A_r",("$%02x\n", data)); |
| 874 | 863 | return data; |
| r5959 | r5960 | |
| 877 | 866 | |
| 878 | 867 | static READ8_DEVICE_HANDLER ( ibm5160_ppi_portc_r ) |
| 879 | 868 | { |
| 880 | | int timer2_output = pit8253_get_output( pc_devices.pit8253, 2 ); |
| 869 | pc_state *st = device->machine->driver_data; |
| 870 | int timer2_output = pit8253_get_output( st->pit8253, 2 ); |
| 881 | 871 | int data=0xff; |
| 882 | 872 | running_machine *machine = device->machine; |
| 883 | 873 | |
| r5959 | r5960 | |
| 885 | 875 | data&=~0x40; // no error on expansion board |
| 886 | 876 | /* KB port C: equipment flags */ |
| 887 | 877 | // if (pc_port[0x61] & 0x08) |
| 888 | | if (pc_ppi.portc_switch_high) |
| 878 | if (st->ppi_portc_switch_high) |
| 889 | 879 | { |
| 890 | 880 | /* read hi nibble of S2 */ |
| 891 | 881 | data = (data & 0xf0) | ((input_port_read(device->machine, "DSW0") >> 4) & 0x0f); |
| r5959 | r5960 | |
| 898 | 888 | PIO_LOG(1,"PIO_C_r (lo)",("$%02x\n", data)); |
| 899 | 889 | } |
| 900 | 890 | |
| 901 | | if ( pc_ppi.portb & 0x01 ) |
| 891 | if ( st->ppi_portb & 0x01 ) |
| 902 | 892 | { |
| 903 | 893 | data = ( data & ~0x10 ) | ( timer2_output ? 0x10 : 0x00 ); |
| 904 | 894 | } |
| r5959 | r5960 | |
| 910 | 900 | |
| 911 | 901 | static WRITE8_DEVICE_HANDLER( ibm5160_ppi_portb_w ) |
| 912 | 902 | { |
| 903 | pc_state *st = device->machine->driver_data; |
| 913 | 904 | /* PPI controller port B*/ |
| 914 | | pc_ppi.portb = data; |
| 915 | | pc_ppi.portc_switch_high = data & 0x08; |
| 916 | | pc_ppi.keyboard_clear = data & 0x80; |
| 917 | | pc_ppi.keyb_clock = data & 0x40; |
| 918 | | pit8253_gate_w( pc_devices.pit8253, 2, data & 0x01 ); |
| 905 | st->ppi_portb = data; |
| 906 | st->ppi_portc_switch_high = data & 0x08; |
| 907 | st->ppi_keyboard_clear = data & 0x80; |
| 908 | st->ppi_keyb_clock = data & 0x40; |
| 909 | pit8253_gate_w( st->pit8253, 2, data & 0x01 ); |
| 919 | 910 | pc_speaker_set_spkrdata( device->machine, data & 0x02 ); |
| 920 | 911 | |
| 921 | | pc_ppi.clock_signal = ( pc_ppi.keyb_clock ) ? 1 : 0; |
| 922 | | pc_ppi.clock_callback( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), 0, pc_ppi.clock_signal ); |
| 912 | st->ppi_clock_signal = ( st->ppi_keyb_clock ) ? 1 : 0; |
| 913 | st->ppi_clock_callback( cpu_get_address_space( device->machine->firstcpu, ADDRESS_SPACE_PROGRAM ), 0, st->ppi_clock_signal ); |
| 923 | 914 | |
| 924 | 915 | /* If PB7 is set clear the shift register and reset the IRQ line */ |
| 925 | | if ( pc_ppi.keyboard_clear ) |
| 916 | if ( st->ppi_keyboard_clear ) |
| 926 | 917 | { |
| 927 | | pic8259_set_irq_line(pc_devices.pic8259, 1, 0); |
| 928 | | pc_ppi.shift_register = 0; |
| 929 | | pc_ppi.shift_enable = 1; |
| 918 | pic8259_set_irq_line(st->pic8259, 1, 0); |
| 919 | st->ppi_shift_register = 0; |
| 920 | st->ppi_shift_enable = 1; |
| 930 | 921 | } |
| 931 | 922 | } |
| 932 | 923 | |
| r5959 | r5960 | |
| 944 | 935 | |
| 945 | 936 | static READ8_DEVICE_HANDLER (pc_ppi_porta_r) |
| 946 | 937 | { |
| 947 | | int data = 0xFF; |
| 938 | int data = 0xFF; |
| 948 | 939 | running_machine *machine = device->machine; |
| 940 | pc_state *st = device->machine->driver_data; |
| 949 | 941 | |
| 950 | 942 | /* KB port A */ |
| 951 | | if (pc_ppi.keyboard_clear) |
| 943 | if (st->ppi_keyboard_clear) |
| 952 | 944 | { |
| 953 | 945 | /* 0 0 - no floppy drives |
| 954 | 946 | * 1 Not used |
| r5959 | r5960 | |
| 972 | 964 | |
| 973 | 965 | static WRITE8_DEVICE_HANDLER( pc_ppi_portb_w ) |
| 974 | 966 | { |
| 967 | pc_state *st = device->machine->driver_data; |
| 975 | 968 | /* PPI controller port B*/ |
| 976 | | pc_ppi.portb = data; |
| 977 | | pc_ppi.portc_switch_high = data & 0x08; |
| 978 | | pc_ppi.keyboard_clear = data & 0x80; |
| 979 | | pc_ppi.keyb_clock = data & 0x40; |
| 980 | | pit8253_gate_w( pc_devices.pit8253, 2, data & 0x01 ); |
| 969 | st->ppi_portb = data; |
| 970 | st->ppi_portc_switch_high = data & 0x08; |
| 971 | st->ppi_keyboard_clear = data & 0x80; |
| 972 | st->ppi_keyb_clock = data & 0x40; |
| 973 | pit8253_gate_w( st->pit8253, 2, data & 0x01 ); |
| 981 | 974 | pc_speaker_set_spkrdata( device->machine, data & 0x02 ); |
| 982 | | pc_keyb_set_clock( pc_ppi.keyb_clock ); |
| 975 | pc_keyb_set_clock( st->ppi_keyb_clock ); |
| 983 | 976 | |
| 984 | | if ( pc_ppi.keyboard_clear ) |
| 977 | if ( st->ppi_keyboard_clear ) |
| 985 | 978 | pc_keyb_clear(); |
| 986 | 979 | } |
| 987 | 980 | |
| r5959 | r5960 | |
| 999 | 992 | |
| 1000 | 993 | static WRITE8_DEVICE_HANDLER ( pcjr_ppi_portb_w ) |
| 1001 | 994 | { |
| 995 | pc_state *st = device->machine->driver_data; |
| 1002 | 996 | /* KB controller port B */ |
| 1003 | | pc_ppi.portb = data; |
| 1004 | | pc_ppi.portc_switch_high = data & 0x08; |
| 997 | st->ppi_portb = data; |
| 998 | st->ppi_portc_switch_high = data & 0x08; |
| 1005 | 999 | pit8253_gate_w( devtag_get_device(device->machine, "pit8253"), 2, data & 1); |
| 1006 | 1000 | pc_speaker_set_spkrdata( device->machine, data & 0x02 ); |
| 1007 | 1001 | |
| r5959 | r5960 | |
| 1036 | 1030 | */ |
| 1037 | 1031 | static READ8_DEVICE_HANDLER ( pcjr_ppi_portc_r ) |
| 1038 | 1032 | { |
| 1033 | pc_state *st = device->machine->driver_data; |
| 1039 | 1034 | int timer2_output = pit8253_get_output( devtag_get_device(device->machine, "pit8253"), 2 ); |
| 1040 | 1035 | int data=0xff; |
| 1041 | 1036 | |
| r5959 | r5960 | |
| 1044 | 1039 | if ( mess_ram_size > 64 * 1024 ) /* more than 64KB ram installed */ |
| 1045 | 1040 | data &= ~0x08; |
| 1046 | 1041 | data = ( data & ~0x01 ) | ( pcjr_keyb.latch ? 0x01: 0x00 ); |
| 1047 | | if ( ! ( pc_ppi.portb & 0x08 ) ) |
| 1042 | if ( ! ( st->ppi_portb & 0x08 ) ) |
| 1048 | 1043 | { |
| 1049 | 1044 | double tap_val = cassette_input( devtag_get_device(device->machine, "cassette") ); |
| 1050 | 1045 | |
| r5959 | r5960 | |
| 1059 | 1054 | } |
| 1060 | 1055 | else |
| 1061 | 1056 | { |
| 1062 | | if ( pc_ppi.portb & 0x01 ) |
| 1057 | if ( st->ppi_portb & 0x01 ) |
| 1063 | 1058 | { |
| 1064 | 1059 | data = ( data & ~0x10 ) | ( timer2_output ? 0x10 : 0x00 ); |
| 1065 | 1060 | } |
| r5959 | r5960 | |
| 1092 | 1087 | |
| 1093 | 1088 | static void pc_fdc_interrupt(running_machine *machine, int state) |
| 1094 | 1089 | { |
| 1095 | | if ( pc_devices.pic8259 ) { |
| 1096 | | pic8259_set_irq_line(pc_devices.pic8259, 6, state); |
| 1090 | pc_state *st = machine->driver_data; |
| 1091 | if ( st->pic8259 ) { |
| 1092 | pic8259_set_irq_line(st->pic8259, 6, state); |
| 1097 | 1093 | } |
| 1098 | 1094 | } |
| 1099 | 1095 | |
| 1100 | 1096 | static void pc_fdc_dma_drq(running_machine *machine, int state, int read_) |
| 1101 | 1097 | { |
| 1102 | | dma8237_drq_write( pc_devices.dma8237, FDC_DMA, state); |
| 1098 | pc_state *st = machine->driver_data; |
| 1099 | dma8237_drq_write( st->dma8237, FDC_DMA, state); |
| 1103 | 1100 | } |
| 1104 | 1101 | |
| 1105 | 1102 | static const device_config * pc_get_device(running_machine *machine ) |
| r5959 | r5960 | |
| 1125 | 1122 | }; |
| 1126 | 1123 | |
| 1127 | 1124 | |
| 1128 | | static void pc_set_irq_line(int irq, int state) { |
| 1129 | | pic8259_set_irq_line(pc_devices.pic8259, irq, state); |
| 1125 | static void pc_set_irq_line(running_machine *machine,int irq, int state) { |
| 1126 | pc_state *st = machine->driver_data; |
| 1127 | pic8259_set_irq_line(st->pic8259, irq, state); |
| 1130 | 1128 | } |
| 1131 | 1129 | |
| 1132 | 1130 | static void pc_set_keyb_int(running_machine *machine, int state) |
| 1133 | 1131 | { |
| 1134 | | pc_set_irq_line( 1, state ); |
| 1132 | pc_set_irq_line( machine, 1, state ); |
| 1135 | 1133 | } |
| 1136 | 1134 | |
| 1137 | 1135 | |
| r5959 | r5960 | |
| 1141 | 1139 | * |
| 1142 | 1140 | **********************************************************/ |
| 1143 | 1141 | |
| 1144 | | void mess_init_pc_common(running_machine *machine, UINT32 flags, void (*set_keyb_int_func)(running_machine *, int), void (*set_hdc_int_func)(int,int)) |
| 1142 | void mess_init_pc_common(running_machine *machine, UINT32 flags, void (*set_keyb_int_func)(running_machine *, int), void (*set_hdc_int_func)(running_machine *,int,int)) |
| 1145 | 1143 | { |
| 1146 | 1144 | if ( set_keyb_int_func != NULL ) |
| 1147 | 1145 | init_pc_common(machine, flags, set_keyb_int_func); |
| r5959 | r5960 | |
| 1335 | 1333 | |
| 1336 | 1334 | static IRQ_CALLBACK(pc_irq_callback) |
| 1337 | 1335 | { |
| 1338 | | return pic8259_acknowledge( pc_devices.pic8259 ); |
| 1336 | pc_state *st = device->machine->driver_data; |
| 1337 | return pic8259_acknowledge( st->pic8259 ); |
| 1339 | 1338 | } |
| 1340 | 1339 | |
| 1341 | 1340 | |
| r5959 | r5960 | |
| 1348 | 1347 | MACHINE_RESET( pc ) |
| 1349 | 1348 | { |
| 1350 | 1349 | const device_config *speaker = devtag_get_device(machine, "speaker"); |
| 1350 | pc_state *st = machine->driver_data; |
| 1351 | memset(st,0,sizeof(st)); |
| 1352 | st->maincpu = devtag_get_device(machine, "maincpu" ); |
| 1353 | cpu_set_irq_callback(st->maincpu, pc_irq_callback); |
| 1351 | 1354 | |
| 1352 | | pc_devices.maincpu = devtag_get_device(machine, "maincpu" ); |
| 1353 | | cpu_set_irq_callback(pc_devices.maincpu, pc_irq_callback); |
| 1354 | | |
| 1355 | | pc_devices.pic8259 = devtag_get_device(machine, "pic8259"); |
| 1356 | | pc_devices.dma8237 = devtag_get_device(machine, "dma8237"); |
| 1357 | | pc_devices.pit8253 = devtag_get_device(machine, "pit8253"); |
| 1358 | | pc_devices.u73_q2 = 0; |
| 1359 | | pc_devices.out1 = 0; |
| 1355 | st->pic8259 = devtag_get_device(machine, "pic8259"); |
| 1356 | st->dma8237 = devtag_get_device(machine, "dma8237"); |
| 1357 | st->pit8253 = devtag_get_device(machine, "pit8253"); |
| 1358 | st->u73_q2 = 0; |
| 1359 | st->out1 = 0; |
| 1360 | st->pc_spkrdata = 0; |
| 1361 | st->pc_input = 0; |
| 1360 | 1362 | pc_mouse_set_serial_port( devtag_get_device(machine, "ins8250_0") ); |
| 1361 | | pc_hdc_set_dma8237_device( pc_devices.dma8237 ); |
| 1363 | pc_hdc_set_dma8237_device( st->dma8237 ); |
| 1362 | 1364 | speaker_level_w( speaker, 0 ); |
| 1363 | 1365 | } |
| 1364 | 1366 | |
| r5959 | r5960 | |
| 1372 | 1374 | MACHINE_RESET( pcjr ) |
| 1373 | 1375 | { |
| 1374 | 1376 | const device_config *speaker = devtag_get_device(machine, "speaker"); |
| 1377 | pc_state *st = machine->driver_data; |
| 1378 | memset(st,0,sizeof(st)); |
| 1379 | st->maincpu = devtag_get_device(machine, "maincpu" ); |
| 1380 | cpu_set_irq_callback(st->maincpu, pc_irq_callback); |
| 1375 | 1381 | |
| 1376 | | pc_devices.maincpu = devtag_get_device(machine, "maincpu" ); |
| 1377 | | cpu_set_irq_callback(pc_devices.maincpu, pc_irq_callback); |
| 1378 | | |
| 1379 | | pc_devices.pic8259 = devtag_get_device(machine, "pic8259"); |
| 1380 | | pc_devices.dma8237 = NULL; |
| 1381 | | pc_devices.pit8253 = devtag_get_device(machine, "pit8253"); |
| 1382 | | pc_devices.u73_q2 = 0; |
| 1383 | | pc_devices.out1 = 0; |
| 1382 | st->pic8259 = devtag_get_device(machine, "pic8259"); |
| 1383 | st->dma8237 = NULL; |
| 1384 | st->pit8253 = devtag_get_device(machine, "pit8253"); |
| 1385 | st->u73_q2 = 0; |
| 1386 | st->out1 = 0; |
| 1387 | st->pc_spkrdata = 0; |
| 1388 | st->pc_input = 0; |
| 1384 | 1389 | pc_mouse_set_serial_port( devtag_get_device(machine, "ins8250_0") ); |
| 1385 | | pc_hdc_set_dma8237_device( pc_devices.dma8237 ); |
| 1390 | pc_hdc_set_dma8237_device( st->dma8237 ); |
| 1386 | 1391 | speaker_level_w( speaker, 0 ); |
| 1387 | 1392 | |
| 1388 | 1393 | pcjr_keyb_init(machine); |