src/mess/machine/rmnimbus.c
| r9685 | r9686 | |
| 62 | 62 | |
| 63 | 63 | /* Debugging */ |
| 64 | 64 | |
| 65 | | #define DEBUG_SET(flags) ((debug_machine & (flags))==(flags)) |
| 66 | | static UINT32 debug_machine; |
| 65 | #define DEBUG_SET(flags) ((state->debug_machine & (flags))==(flags)) |
| 67 | 66 | |
| 68 | 67 | #define DMA_BREAK 0x0000001 |
| 69 | 68 | #define DECODE_BIOS 0x0000002 |
| 70 | 69 | |
| 71 | | /* 80186 internal stuff */ |
| 72 | | struct mem_state |
| 73 | | { |
| 74 | | UINT16 lower; |
| 75 | | UINT16 upper; |
| 76 | | UINT16 middle; |
| 77 | | UINT16 middle_size; |
| 78 | | UINT16 peripheral; |
| 79 | | }; |
| 80 | | |
| 81 | | struct timer_state |
| 82 | | { |
| 83 | | UINT16 control; |
| 84 | | UINT16 maxA; |
| 85 | | UINT16 maxB; |
| 86 | | UINT16 count; |
| 87 | | emu_timer *int_timer; |
| 88 | | emu_timer *time_timer; |
| 89 | | UINT8 time_timer_active; |
| 90 | | attotime last_time; |
| 91 | | }; |
| 92 | | |
| 93 | | struct dma_state |
| 94 | | { |
| 95 | | UINT32 source; |
| 96 | | UINT32 dest; |
| 97 | | UINT16 count; |
| 98 | | UINT16 control; |
| 99 | | UINT8 finished; |
| 100 | | emu_timer *finish_timer; |
| 101 | | }; |
| 102 | | |
| 103 | | struct intr_state |
| 104 | | { |
| 105 | | UINT8 pending; |
| 106 | | UINT16 ack_mask; |
| 107 | | UINT16 priority_mask; |
| 108 | | UINT16 in_service; |
| 109 | | UINT16 request; |
| 110 | | UINT16 status; |
| 111 | | UINT16 poll_status; |
| 112 | | UINT16 timer; |
| 113 | | UINT16 dma[2]; |
| 114 | | UINT16 ext[4]; |
| 115 | | UINT16 ext_vector[2]; // external vectors, when in cascade mode |
| 116 | | }; |
| 117 | | |
| 118 | | static struct i186_state |
| 119 | | { |
| 120 | | struct timer_state timer[3]; |
| 121 | | struct dma_state dma[2]; |
| 122 | | struct intr_state intr; |
| 123 | | struct mem_state mem; |
| 124 | | } i186; |
| 125 | | |
| 126 | | |
| 127 | 70 | /* Z80 SIO */ |
| 128 | 71 | |
| 129 | 72 | const z80sio_interface nimbus_sio_intf = |
| r9685 | r9686 | |
| 136 | 79 | sio_serial_receive /* receive handler */ |
| 137 | 80 | }; |
| 138 | 81 | |
| 139 | | static struct keyboard_state |
| 140 | | { |
| 141 | | UINT8 keyrows[NIMBUS_KEYROWS]; |
| 142 | | emu_timer *keyscan_timer; |
| 143 | | UINT8 queue[KEYBOARD_QUEUE_SIZE]; |
| 144 | | UINT8 head; |
| 145 | | UINT8 tail; |
| 146 | | } keyboard; |
| 147 | | |
| 148 | 82 | /* Floppy drives WD2793 */ |
| 149 | 83 | |
| 150 | 84 | static WRITE_LINE_DEVICE_HANDLER( nimbus_fdc_intrq_w ); |
| r9685 | r9686 | |
| 159 | 93 | }; |
| 160 | 94 | |
| 161 | 95 | |
| 162 | | // Static data related to Floppy and SCSI hard disks |
| 163 | | static struct _nimbus_drives |
| 164 | | { |
| 165 | | UINT8 reg400; |
| 166 | | UINT8 reg410_in; |
| 167 | | UINT8 reg410_out; |
| 168 | | UINT8 reg418; |
| 169 | | |
| 170 | | UINT8 drq_ff; |
| 171 | | UINT8 int_ff; |
| 172 | | } nimbus_drives; |
| 173 | | |
| 174 | | |
| 175 | | /* 8031 Peripheral controler */ |
| 176 | | static struct _ipc_interface |
| 177 | | { |
| 178 | | UINT8 ipc_in; |
| 179 | | UINT8 ipc_out; |
| 180 | | UINT8 status_in; |
| 181 | | UINT8 status_out; |
| 182 | | UINT8 int_8c_pending; |
| 183 | | UINT8 int_8e_pending; |
| 184 | | UINT8 int_8f_pending; |
| 185 | | } ipc_interface; |
| 186 | | |
| 187 | 96 | static const UINT16 def_config[16] = |
| 188 | 97 | { |
| 189 | 98 | 0x0280, 0x017F, 0xE822, 0x8129, |
| r9685 | r9686 | |
| 193 | 102 | }; |
| 194 | 103 | |
| 195 | 104 | /* Memory controler */ |
| 196 | | static UINT8 mcu_reg080; |
| 197 | 105 | |
| 198 | 106 | /* IO Unit */ |
| 199 | | static UINT8 iou_reg092; |
| 200 | 107 | |
| 201 | 108 | /* Sound */ |
| 202 | | static UINT8 last_playmode; |
| 203 | 109 | |
| 204 | | /* Mouse/Joystick */ |
| 205 | 110 | |
| 206 | | typedef struct |
| 207 | | { |
| 208 | | UINT8 mouse_px; |
| 209 | | UINT8 mouse_py; |
| 210 | | |
| 211 | | UINT8 mouse_x; |
| 212 | | UINT8 mouse_y; |
| 213 | | UINT8 mouse_pc; |
| 214 | | UINT8 mouse_pcx; |
| 215 | | UINT8 mouse_pcy; |
| 216 | | |
| 217 | | UINT8 intstate_x; |
| 218 | | UINT8 intstate_y; |
| 219 | | |
| 220 | | UINT8 reg0a4; |
| 221 | | |
| 222 | | emu_timer *mouse_timer; |
| 223 | | } _mouse_joy_state; |
| 224 | | |
| 225 | | static _mouse_joy_state nimbus_mouse; |
| 226 | | static UINT8 ay8910_a; |
| 227 | | |
| 228 | 111 | static void drq_callback(running_machine *machine, int which); |
| 229 | 112 | static void nimbus_recalculate_ints(running_machine *machine); |
| 230 | 113 | |
| r9685 | r9686 | |
| 259 | 142 | static void mouse_js_reset(running_machine *machine); |
| 260 | 143 | static TIMER_CALLBACK(mouse_callback); |
| 261 | 144 | |
| 262 | | #define num_ioports 0x80 |
| 263 | | static UINT16 IOPorts[num_ioports]; |
| 264 | 145 | |
| 265 | | static UINT8 sio_int_state; |
| 266 | | |
| 267 | 146 | /************************************* |
| 268 | 147 | * |
| 269 | 148 | * 80186 interrupt controller |
| r9685 | r9686 | |
| 271 | 150 | *************************************/ |
| 272 | 151 | static IRQ_CALLBACK(int_callback) |
| 273 | 152 | { |
| 153 | rmnimbus_state *state = device->machine->driver_data<rmnimbus_state>(); |
| 274 | 154 | UINT8 vector; |
| 275 | 155 | UINT16 old; |
| 276 | 156 | UINT16 oldreq; |
| 277 | 157 | |
| 278 | 158 | if (LOG_INTERRUPTS) |
| 279 | | logerror("(%f) **** Acknowledged interrupt vector %02X\n", attotime_to_double(timer_get_time(device->machine)), i186.intr.poll_status & 0x1f); |
| 159 | logerror("(%f) **** Acknowledged interrupt vector %02X\n", attotime_to_double(timer_get_time(device->machine)), state->i186.intr.poll_status & 0x1f); |
| 280 | 160 | |
| 281 | 161 | /* clear the interrupt */ |
| 282 | 162 | cpu_set_input_line(device, 0, CLEAR_LINE); |
| 283 | | i186.intr.pending = 0; |
| 163 | state->i186.intr.pending = 0; |
| 284 | 164 | |
| 285 | | oldreq=i186.intr.request; |
| 165 | oldreq=state->i186.intr.request; |
| 286 | 166 | |
| 287 | 167 | /* clear the request and set the in-service bit */ |
| 288 | 168 | #if LATCH_INTS |
| 289 | | i186.intr.request &= ~i186.intr.ack_mask; |
| 169 | state->i186.intr.request &= ~state->i186.intr.ack_mask; |
| 290 | 170 | #else |
| 291 | | i186.intr.request &= ~(i186.intr.ack_mask & 0x0f); |
| 171 | state->i186.intr.request &= ~(state->i186.intr.ack_mask & 0x0f); |
| 292 | 172 | #endif |
| 293 | 173 | |
| 294 | | if((LOG_INTERRUPTS) && (i186.intr.request!=oldreq)) |
| 295 | | logerror("i186.intr.request changed from %02X to %02X\n",oldreq,i186.intr.request); |
| 174 | if((LOG_INTERRUPTS) && (state->i186.intr.request!=oldreq)) |
| 175 | logerror("i186.intr.request changed from %02X to %02X\n",oldreq,state->i186.intr.request); |
| 296 | 176 | |
| 297 | | old=i186.intr.in_service; |
| 177 | old=state->i186.intr.in_service; |
| 298 | 178 | |
| 299 | | i186.intr.in_service |= i186.intr.ack_mask; |
| 179 | state->i186.intr.in_service |= state->i186.intr.ack_mask; |
| 300 | 180 | |
| 301 | | if((LOG_INTERRUPTS) && (i186.intr.in_service!=old)) |
| 302 | | logerror("i186.intr.in_service changed from %02X to %02X\n",old,i186.intr.in_service); |
| 181 | if((LOG_INTERRUPTS) && (state->i186.intr.in_service!=old)) |
| 182 | logerror("i186.intr.in_service changed from %02X to %02X\n",old,state->i186.intr.in_service); |
| 303 | 183 | |
| 304 | | if (i186.intr.ack_mask == 0x0001) |
| 184 | if (state->i186.intr.ack_mask == 0x0001) |
| 305 | 185 | { |
| 306 | | switch (i186.intr.poll_status & 0x1f) |
| 186 | switch (state->i186.intr.poll_status & 0x1f) |
| 307 | 187 | { |
| 308 | | case 0x08: i186.intr.status &= ~0x01; break; |
| 309 | | case 0x12: i186.intr.status &= ~0x02; break; |
| 310 | | case 0x13: i186.intr.status &= ~0x04; break; |
| 188 | case 0x08: state->i186.intr.status &= ~0x01; break; |
| 189 | case 0x12: state->i186.intr.status &= ~0x02; break; |
| 190 | case 0x13: state->i186.intr.status &= ~0x04; break; |
| 311 | 191 | } |
| 312 | 192 | } |
| 313 | | i186.intr.ack_mask = 0; |
| 193 | state->i186.intr.ack_mask = 0; |
| 314 | 194 | |
| 315 | 195 | /* a request no longer pending */ |
| 316 | | i186.intr.poll_status &= ~0x8000; |
| 196 | state->i186.intr.poll_status &= ~0x8000; |
| 317 | 197 | |
| 318 | 198 | /* return the vector */ |
| 319 | | switch(i186.intr.poll_status & 0x1F) |
| 199 | switch(state->i186.intr.poll_status & 0x1F) |
| 320 | 200 | { |
| 321 | | case 0x0C : vector=(i186.intr.ext[0] & EXTINT_CTRL_CASCADE) ? i186.intr.ext_vector[0] : (i186.intr.poll_status & 0x1f); break; |
| 322 | | case 0x0D : vector=(i186.intr.ext[1] & EXTINT_CTRL_CASCADE) ? i186.intr.ext_vector[1] : (i186.intr.poll_status & 0x1f); break; |
| 201 | case 0x0C : vector=(state->i186.intr.ext[0] & EXTINT_CTRL_CASCADE) ? state->i186.intr.ext_vector[0] : (state->i186.intr.poll_status & 0x1f); break; |
| 202 | case 0x0D : vector=(state->i186.intr.ext[1] & EXTINT_CTRL_CASCADE) ? state->i186.intr.ext_vector[1] : (state->i186.intr.poll_status & 0x1f); break; |
| 323 | 203 | default : |
| 324 | | vector=i186.intr.poll_status & 0x1f; break; |
| 204 | vector=state->i186.intr.poll_status & 0x1f; break; |
| 325 | 205 | } |
| 326 | 206 | |
| 327 | 207 | if (LOG_INTERRUPTS) |
| 328 | | { |
| 329 | | logerror("i186.intr.ext[0]=%04X i186.intr.ext[1]=%04X\n",i186.intr.ext[0],i186.intr.ext[1]); |
| 330 | | logerror("Ext vectors : %02X %02X\n",i186.intr.ext_vector[0],i186.intr.ext_vector[1]); |
| 331 | | logerror("Int %02X Calling vector %02X\n",i186.intr.poll_status,vector); |
| 208 | { |
| 209 | logerror("i186.intr.ext[0]=%04X i186.intr.ext[1]=%04X\n",state->i186.intr.ext[0],state->i186.intr.ext[1]); |
| 210 | logerror("Ext vectors : %02X %02X\n",state->i186.intr.ext_vector[0],state->i186.intr.ext_vector[1]); |
| 211 | logerror("Int %02X Calling vector %02X\n",state->i186.intr.poll_status,vector); |
| 332 | 212 | } |
| 333 | 213 | |
| 334 | 214 | return vector; |
| r9685 | r9686 | |
| 337 | 217 | |
| 338 | 218 | static void update_interrupt_state(running_machine *machine) |
| 339 | 219 | { |
| 340 | | int new_vector = 0; |
| 341 | | int Priority; |
| 342 | | int IntNo; |
| 220 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 221 | int new_vector = 0; |
| 222 | int Priority; |
| 223 | int IntNo; |
| 343 | 224 | |
| 344 | 225 | if (LOG_INTERRUPTS) |
| 345 | | logerror("update_interrupt_status: req=%04X stat=%04X serv=%04X priority_mask=%4X\n", i186.intr.request, i186.intr.status, i186.intr.in_service, i186.intr.priority_mask); |
| 226 | logerror("update_interrupt_status: req=%04X stat=%04X serv=%04X priority_mask=%4X\n", state->i186.intr.request, state->i186.intr.status, state->i186.intr.in_service, state->i186.intr.priority_mask); |
| 346 | 227 | |
| 347 | 228 | /* loop over priorities */ |
| 348 | | for (Priority = 0; Priority <= i186.intr.priority_mask; Priority++) |
| 229 | for (Priority = 0; Priority <= state->i186.intr.priority_mask; Priority++) |
| 349 | 230 | { |
| 350 | 231 | /* note: by checking 4 bits, we also verify that the mask is off */ |
| 351 | | if ((i186.intr.timer & 0x0F) == Priority) |
| 232 | if ((state->i186.intr.timer & 0x0F) == Priority) |
| 352 | 233 | { |
| 353 | 234 | /* if we're already servicing something at this level, don't generate anything new */ |
| 354 | | if (i186.intr.in_service & 0x01) |
| 235 | if (state->i186.intr.in_service & 0x01) |
| 355 | 236 | return; |
| 356 | 237 | |
| 357 | 238 | /* if there's something pending, generate an interrupt */ |
| 358 | | if (i186.intr.status & 0x07) |
| 239 | if (state->i186.intr.status & 0x07) |
| 359 | 240 | { |
| 360 | | if (i186.intr.status & 1) |
| 241 | if (state->i186.intr.status & 1) |
| 361 | 242 | new_vector = 0x08; |
| 362 | | else if (i186.intr.status & 2) |
| 243 | else if (state->i186.intr.status & 2) |
| 363 | 244 | new_vector = 0x12; |
| 364 | | else if (i186.intr.status & 4) |
| 245 | else if (state->i186.intr.status & 4) |
| 365 | 246 | new_vector = 0x13; |
| 366 | 247 | else |
| 367 | 248 | popmessage("Invalid timer interrupt!"); |
| 368 | 249 | |
| 369 | 250 | /* set the clear mask and generate the int */ |
| 370 | | i186.intr.ack_mask = 0x0001; |
| 251 | state->i186.intr.ack_mask = 0x0001; |
| 371 | 252 | goto generate_int; |
| 372 | 253 | } |
| 373 | 254 | } |
| 374 | 255 | |
| 375 | 256 | /* check DMA interrupts */ |
| 376 | 257 | for (IntNo = 0; IntNo < 2; IntNo++) |
| 377 | | if ((i186.intr.dma[IntNo] & 0x0F) == Priority) |
| 258 | if ((state->i186.intr.dma[IntNo] & 0x0F) == Priority) |
| 378 | 259 | { |
| 379 | 260 | /* if we're already servicing something at this level, don't generate anything new */ |
| 380 | | if (i186.intr.in_service & (0x04 << IntNo)) |
| 261 | if (state->i186.intr.in_service & (0x04 << IntNo)) |
| 381 | 262 | return; |
| 382 | 263 | |
| 383 | 264 | /* if there's something pending, generate an interrupt */ |
| 384 | | if (i186.intr.request & (0x04 << IntNo)) |
| 265 | if (state->i186.intr.request & (0x04 << IntNo)) |
| 385 | 266 | { |
| 386 | 267 | new_vector = 0x0a + IntNo; |
| 387 | 268 | |
| 388 | 269 | /* set the clear mask and generate the int */ |
| 389 | | i186.intr.ack_mask = 0x0004 << IntNo; |
| 270 | state->i186.intr.ack_mask = 0x0004 << IntNo; |
| 390 | 271 | goto generate_int; |
| 391 | 272 | } |
| 392 | 273 | } |
| 393 | 274 | |
| 394 | | /* check external interrupts */ |
| 275 | /* check external interrupts */ |
| 395 | 276 | for (IntNo = 0; IntNo < 4; IntNo++) |
| 396 | | if ((i186.intr.ext[IntNo] & 0x0F) == Priority) |
| 277 | if ((state->i186.intr.ext[IntNo] & 0x0F) == Priority) |
| 397 | 278 | { |
| 398 | | if (LOG_INTERRUPTS) |
| 399 | | logerror("Int%d priority=%d\n",IntNo,Priority); |
| 279 | if (LOG_INTERRUPTS) |
| 280 | logerror("Int%d priority=%d\n",IntNo,Priority); |
| 400 | 281 | |
| 401 | | /* if we're already servicing something at this level, don't generate anything new */ |
| 402 | | if (i186.intr.in_service & (0x10 << IntNo)) |
| 282 | /* if we're already servicing something at this level, don't generate anything new */ |
| 283 | if (state->i186.intr.in_service & (0x10 << IntNo)) |
| 403 | 284 | return; |
| 404 | 285 | |
| 405 | 286 | /* if there's something pending, generate an interrupt */ |
| 406 | | if (i186.intr.request & (0x10 << IntNo)) |
| 287 | if (state->i186.intr.request & (0x10 << IntNo)) |
| 407 | 288 | { |
| 408 | 289 | /* otherwise, generate an interrupt for this request */ |
| 409 | 290 | new_vector = 0x0c + IntNo; |
| 410 | 291 | |
| 411 | 292 | /* set the clear mask and generate the int */ |
| 412 | | i186.intr.ack_mask = 0x0010 << IntNo; |
| 413 | | goto generate_int; |
| 293 | state->i186.intr.ack_mask = 0x0010 << IntNo; |
| 294 | goto generate_int; |
| 414 | 295 | } |
| 415 | 296 | } |
| 416 | 297 | } |
| r9685 | r9686 | |
| 418 | 299 | |
| 419 | 300 | generate_int: |
| 420 | 301 | /* generate the appropriate interrupt */ |
| 421 | | i186.intr.poll_status = 0x8000 | new_vector; |
| 422 | | if (!i186.intr.pending) |
| 302 | state->i186.intr.poll_status = 0x8000 | new_vector; |
| 303 | if (!state->i186.intr.pending) |
| 423 | 304 | cputag_set_input_line(machine, MAINCPU_TAG, 0, ASSERT_LINE); |
| 424 | | i186.intr.pending = 1; |
| 305 | state->i186.intr.pending = 1; |
| 425 | 306 | cpuexec_trigger(machine, CPU_RESUME_TRIGGER); |
| 426 | 307 | if (LOG_OPTIMIZATION) logerror(" - trigger due to interrupt pending\n"); |
| 427 | 308 | if (LOG_INTERRUPTS) logerror("(%f) **** Requesting interrupt vector %02X\n", attotime_to_double(timer_get_time(machine)), new_vector); |
| r9685 | r9686 | |
| 430 | 311 | |
| 431 | 312 | static void handle_eoi(running_machine *machine,int data) |
| 432 | 313 | { |
| 433 | | int Priority; |
| 434 | | int IntNo; |
| 435 | | int handled=0; |
| 314 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 315 | int Priority; |
| 316 | int IntNo; |
| 317 | int handled=0; |
| 436 | 318 | |
| 437 | 319 | /* specific case */ |
| 438 | 320 | if (!(data & 0x8000)) |
| r9685 | r9686 | |
| 440 | 322 | /* turn off the appropriate in-service bit */ |
| 441 | 323 | switch (data & 0x1f) |
| 442 | 324 | { |
| 443 | | case 0x08: i186.intr.in_service &= ~0x01; break; |
| 444 | | case 0x12: i186.intr.in_service &= ~0x01; break; |
| 445 | | case 0x13: i186.intr.in_service &= ~0x01; break; |
| 446 | | case 0x0a: i186.intr.in_service &= ~0x04; break; |
| 447 | | case 0x0b: i186.intr.in_service &= ~0x08; break; |
| 448 | | case 0x0c: i186.intr.in_service &= ~0x10; break; |
| 449 | | case 0x0d: i186.intr.in_service &= ~0x20; break; |
| 450 | | case 0x0e: i186.intr.in_service &= ~0x40; break; |
| 451 | | case 0x0f: i186.intr.in_service &= ~0x80; break; |
| 325 | case 0x08: state->i186.intr.in_service &= ~0x01; break; |
| 326 | case 0x12: state->i186.intr.in_service &= ~0x01; break; |
| 327 | case 0x13: state->i186.intr.in_service &= ~0x01; break; |
| 328 | case 0x0a: state->i186.intr.in_service &= ~0x04; break; |
| 329 | case 0x0b: state->i186.intr.in_service &= ~0x08; break; |
| 330 | case 0x0c: state->i186.intr.in_service &= ~0x10; break; |
| 331 | case 0x0d: state->i186.intr.in_service &= ~0x20; break; |
| 332 | case 0x0e: state->i186.intr.in_service &= ~0x40; break; |
| 333 | case 0x0f: state->i186.intr.in_service &= ~0x80; break; |
| 452 | 334 | default: logerror("%05X:ERROR - 80186 EOI with unknown vector %02X\n", cpu_get_pc(machine->device(MAINCPU_TAG)), data & 0x1f); |
| 453 | 335 | } |
| 454 | 336 | if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for vector %02X\n", attotime_to_double(timer_get_time(machine)), data & 0x1f); |
| r9685 | r9686 | |
| 461 | 343 | for (Priority = 0; ((Priority <= 7) && !handled); Priority++) |
| 462 | 344 | { |
| 463 | 345 | /* check for in-service timers */ |
| 464 | | if ((i186.intr.timer & 0x07) == Priority && (i186.intr.in_service & 0x01)) |
| 346 | if ((state->i186.intr.timer & 0x07) == Priority && (state->i186.intr.in_service & 0x01)) |
| 465 | 347 | { |
| 466 | | i186.intr.in_service &= ~0x01; |
| 348 | state->i186.intr.in_service &= ~0x01; |
| 467 | 349 | if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for timer\n", attotime_to_double(timer_get_time(machine))); |
| 468 | 350 | handled=1; |
| 469 | 351 | } |
| 470 | 352 | |
| 471 | 353 | /* check for in-service DMA interrupts */ |
| 472 | 354 | for (IntNo = 0; ((IntNo < 2) && !handled) ; IntNo++) |
| 473 | | if ((i186.intr.dma[IntNo] & 0x07) == Priority && (i186.intr.in_service & (0x04 << IntNo))) |
| 355 | if ((state->i186.intr.dma[IntNo] & 0x07) == Priority && (state->i186.intr.in_service & (0x04 << IntNo))) |
| 474 | 356 | { |
| 475 | | i186.intr.in_service &= ~(0x04 << IntNo); |
| 357 | state->i186.intr.in_service &= ~(0x04 << IntNo); |
| 476 | 358 | if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for DMA%d\n", attotime_to_double(timer_get_time(machine)), IntNo); |
| 477 | 359 | handled=1; |
| 478 | 360 | } |
| 479 | 361 | |
| 480 | 362 | /* check external interrupts */ |
| 481 | 363 | for (IntNo = 0; ((IntNo < 4) && !handled) ; IntNo++) |
| 482 | | if ((i186.intr.ext[IntNo] & 0x07) == Priority && (i186.intr.in_service & (0x10 << IntNo))) |
| 364 | if ((state->i186.intr.ext[IntNo] & 0x07) == Priority && (state->i186.intr.in_service & (0x10 << IntNo))) |
| 483 | 365 | { |
| 484 | | i186.intr.in_service &= ~(0x10 << IntNo); |
| 366 | state->i186.intr.in_service &= ~(0x10 << IntNo); |
| 485 | 367 | if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for INT%d\n", attotime_to_double(timer_get_time(machine)), IntNo); |
| 486 | 368 | handled=1; |
| 487 | 369 | } |
| 488 | 370 | } |
| 489 | 371 | } |
| 490 | | nimbus_recalculate_ints(machine); |
| 372 | nimbus_recalculate_ints(machine); |
| 491 | 373 | } |
| 492 | 374 | |
| 493 | 375 | /* Trigger an external interupt, optionally supplying the vector to take */ |
| 494 | 376 | static void external_int(running_machine *machine, UINT16 intno, UINT8 vector) |
| 495 | 377 | { |
| 378 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 496 | 379 | if (LOG_INTERRUPTS_EXT) logerror("generating external int %02X, vector %02X\n",intno,vector); |
| 497 | 380 | |
| 498 | 381 | // Only 4 external ints |
| r9685 | r9686 | |
| 506 | 389 | // int 0 & int 1 |
| 507 | 390 | if (intno<2) |
| 508 | 391 | { |
| 509 | | if(i186.intr.ext[intno] & EXTINT_CTRL_CASCADE) |
| 510 | | i186.intr.ext_vector[intno]=vector; |
| 392 | if(state->i186.intr.ext[intno] & EXTINT_CTRL_CASCADE) |
| 393 | state->i186.intr.ext_vector[intno]=vector; |
| 511 | 394 | } |
| 512 | 395 | |
| 513 | 396 | // Turn on the requested request bit and handle interrupt |
| 514 | | i186.intr.request |= (0x010 << intno); |
| 397 | state->i186.intr.request |= (0x010 << intno); |
| 515 | 398 | update_interrupt_state(machine); |
| 516 | 399 | } |
| 517 | 400 | |
| 518 | 401 | static void nimbus_recalculate_ints(running_machine *machine) |
| 519 | 402 | { |
| 520 | | if((iou_reg092 & DISK_INT_ENABLE) && nimbus_drives.int_ff) |
| 403 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 404 | if((state->iou_reg092 & DISK_INT_ENABLE) && state->nimbus_drives.int_ff) |
| 521 | 405 | { |
| 522 | | nimbus_drives.int_ff=0; |
| 406 | state->nimbus_drives.int_ff=0; |
| 523 | 407 | external_int(machine,0,EXTERNAL_INT_DISK); |
| 524 | 408 | } |
| 525 | 409 | } |
| r9685 | r9686 | |
| 532 | 416 | |
| 533 | 417 | static TIMER_CALLBACK(internal_timer_int) |
| 534 | 418 | { |
| 419 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 535 | 420 | int which = param; |
| 536 | | struct timer_state *t = &i186.timer[which]; |
| 421 | struct timer_state *t = &state->i186.timer[which]; |
| 537 | 422 | |
| 538 | 423 | if (LOG_TIMER) logerror("Hit interrupt callback for timer %d\n", which); |
| 539 | 424 | |
| r9685 | r9686 | |
| 543 | 428 | /* request an interrupt */ |
| 544 | 429 | if (t->control & 0x2000) |
| 545 | 430 | { |
| 546 | | i186.intr.status |= 0x01 << which; |
| 431 | state->i186.intr.status |= 0x01 << which; |
| 547 | 432 | update_interrupt_state(machine); |
| 548 | 433 | if (LOG_TIMER) logerror(" Generating timer interrupt\n"); |
| 549 | 434 | } |
| r9685 | r9686 | |
| 560 | 445 | } |
| 561 | 446 | |
| 562 | 447 | |
| 563 | | static void internal_timer_sync(int which) |
| 448 | static void internal_timer_sync(running_machine *machine, int which) |
| 564 | 449 | { |
| 565 | | struct timer_state *t = &i186.timer[which]; |
| 450 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 451 | struct timer_state *t = &state->i186.timer[which]; |
| 566 | 452 | |
| 567 | 453 | /* if we have a timing timer running, adjust the count */ |
| 568 | 454 | if (t->time_timer_active) |
| r9685 | r9686 | |
| 585 | 471 | |
| 586 | 472 | |
| 587 | 473 | static void internal_timer_update(running_machine *machine, |
| 588 | | int which, |
| 474 | int which, |
| 589 | 475 | int new_count, |
| 590 | 476 | int new_maxA, |
| 591 | 477 | int new_maxB, |
| 592 | 478 | int new_control) |
| 593 | 479 | { |
| 594 | | struct timer_state *t = &i186.timer[which]; |
| 480 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 481 | struct timer_state *t = &state->i186.timer[which]; |
| 595 | 482 | int update_int_timer = 0; |
| 596 | 483 | |
| 597 | | if (LOG_TIMER) |
| 598 | | logerror("internal_timer_update: %d, new_count=%d, new_maxA=%d, new_maxB=%d,new_control=%d\n",which,new_count,new_maxA,new_maxB,new_control); |
| 484 | if (LOG_TIMER) |
| 485 | logerror("internal_timer_update: %d, new_count=%d, new_maxA=%d, new_maxB=%d,new_control=%d\n",which,new_count,new_maxA,new_maxB,new_control); |
| 599 | 486 | |
| 600 | 487 | /* if we have a new count and we're on, update things */ |
| 601 | 488 | if (new_count != -1) |
| 602 | 489 | { |
| 603 | 490 | if (t->control & 0x8000) |
| 604 | 491 | { |
| 605 | | internal_timer_sync(which); |
| 492 | internal_timer_sync(machine, which); |
| 606 | 493 | update_int_timer = 1; |
| 607 | 494 | } |
| 608 | 495 | t->count = new_count; |
| r9685 | r9686 | |
| 613 | 500 | { |
| 614 | 501 | if (t->control & 0x8000) |
| 615 | 502 | { |
| 616 | | internal_timer_sync(which); |
| 503 | internal_timer_sync(machine, which); |
| 617 | 504 | update_int_timer = 1; |
| 618 | 505 | } |
| 619 | 506 | t->maxA = new_maxA; |
| r9685 | r9686 | |
| 628 | 515 | { |
| 629 | 516 | if (t->control & 0x8000) |
| 630 | 517 | { |
| 631 | | internal_timer_sync(which); |
| 518 | internal_timer_sync(machine, which); |
| 632 | 519 | update_int_timer = 1; |
| 633 | 520 | } |
| 634 | 521 | |
| r9685 | r9686 | |
| 657 | 544 | /* check for control bits we don't handle */ |
| 658 | 545 | diff = new_control ^ t->control; |
| 659 | 546 | if (diff & 0x001c) |
| 660 | | logerror("%05X:ERROR! -unsupported timer mode %04X\n", |
| 547 | logerror("%05X:ERROR! -unsupported timer mode %04X\n", |
| 661 | 548 | cpu_get_pc(machine->device(MAINCPU_TAG)), new_control); |
| 662 | 549 | |
| 663 | 550 | /* if we have real changes, update things */ |
| r9685 | r9686 | |
| 668 | 555 | if ((diff & 0x8000) && !(new_control & 0x8000)) |
| 669 | 556 | { |
| 670 | 557 | /* compute the final count */ |
| 671 | | internal_timer_sync(which); |
| 558 | internal_timer_sync(machine, which); |
| 672 | 559 | |
| 673 | 560 | /* nuke the timer and force the interrupt timer to be recomputed */ |
| 674 | 561 | timer_adjust_oneshot(t->time_timer, attotime_never, which); |
| r9685 | r9686 | |
| 688 | 575 | /* if something about the interrupt timer changed, force an update */ |
| 689 | 576 | if (!(diff & 0x8000) && (diff & 0x2000)) |
| 690 | 577 | { |
| 691 | | internal_timer_sync(which); |
| 578 | internal_timer_sync(machine, which); |
| 692 | 579 | update_int_timer = 1; |
| 693 | 580 | } |
| 694 | 581 | } |
| r9685 | r9686 | |
| 700 | 587 | /* update the interrupt timer */ |
| 701 | 588 | if (update_int_timer) |
| 702 | 589 | { |
| 703 | | if ((t->control & 0x8000) && (t->control & 0x2000)) |
| 704 | | { |
| 705 | | int diff = t->maxA - t->count; |
| 706 | | if (diff <= 0) |
| 707 | | diff += 0x10000; |
| 708 | | timer_adjust_oneshot(t->int_timer, attotime_mul(ATTOTIME_IN_HZ(2000000), diff), which); |
| 709 | | if (LOG_TIMER) logerror("Set interrupt timer for %d\n", which); |
| 710 | | } |
| 711 | | else |
| 712 | | { |
| 713 | | timer_adjust_oneshot(t->int_timer, attotime_never, which); |
| 714 | | } |
| 590 | if ((t->control & 0x8000) && (t->control & 0x2000)) |
| 591 | { |
| 592 | int diff = t->maxA - t->count; |
| 593 | if (diff <= 0) |
| 594 | diff += 0x10000; |
| 595 | timer_adjust_oneshot(t->int_timer, attotime_mul(ATTOTIME_IN_HZ(2000000), diff), which); |
| 596 | if (LOG_TIMER) logerror("Set interrupt timer for %d\n", which); |
| 597 | } |
| 598 | else |
| 599 | { |
| 600 | timer_adjust_oneshot(t->int_timer, attotime_never, which); |
| 601 | } |
| 715 | 602 | } |
| 716 | 603 | } |
| 717 | 604 | |
| r9685 | r9686 | |
| 725 | 612 | |
| 726 | 613 | static TIMER_CALLBACK(dma_timer_callback) |
| 727 | 614 | { |
| 615 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 728 | 616 | int which = param; |
| 729 | | struct dma_state *d = &i186.dma[which]; |
| 617 | struct dma_state *d = &state->i186.dma[which]; |
| 730 | 618 | |
| 731 | 619 | /* complete the status update */ |
| 732 | 620 | d->control &= ~0x0002; |
| r9685 | r9686 | |
| 737 | 625 | if (d->control & 0x0100) |
| 738 | 626 | { |
| 739 | 627 | if (LOG_DMA>1) logerror("DMA%d timer callback - requesting interrupt: count = %04X, source = %04X\n", which, d->count, d->source); |
| 740 | | i186.intr.request |= 0x04 << which; |
| 628 | state->i186.intr.request |= 0x04 << which; |
| 741 | 629 | update_interrupt_state(machine); |
| 742 | 630 | } |
| 743 | 631 | } |
| r9685 | r9686 | |
| 745 | 633 | |
| 746 | 634 | static void update_dma_control(running_machine *machine, int which, int new_control) |
| 747 | 635 | { |
| 748 | | struct dma_state *d = &i186.dma[which]; |
| 636 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 637 | struct dma_state *d = &state->i186.dma[which]; |
| 749 | 638 | int diff; |
| 750 | 639 | |
| 751 | 640 | /* handle the CHG bit */ |
| 752 | 641 | if (!(new_control & CHG_NOCHG)) |
| 753 | | new_control = (new_control & ~ST_STOP) | (d->control & ST_STOP); |
| 642 | new_control = (new_control & ~ST_STOP) | (d->control & ST_STOP); |
| 754 | 643 | new_control &= ~CHG_NOCHG; |
| 755 | 644 | |
| 756 | 645 | /* check for control bits we don't handle */ |
| 757 | 646 | diff = new_control ^ d->control; |
| 758 | 647 | if ((LOG_DMA) && (diff & 0x6811)) |
| 759 | | logerror("%05X:ERROR! - unsupported DMA mode %04X\n", |
| 760 | | cpu_get_pc(machine->device(MAINCPU_TAG)), new_control); |
| 648 | logerror("%05X:ERROR! - unsupported DMA mode %04X\n", |
| 649 | cpu_get_pc(machine->device(MAINCPU_TAG)), new_control); |
| 761 | 650 | |
| 762 | 651 | /* if we're going live, set a timer */ |
| 763 | 652 | if ((diff & 0x0002) && (new_control & 0x0002)) |
| r9685 | r9686 | |
| 783 | 672 | } |
| 784 | 673 | } |
| 785 | 674 | |
| 786 | | if (LOG_DMA) logerror("Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); |
| 787 | | if (DEBUG_SET(DMA_BREAK)) |
| 788 | | debugger_break(machine); |
| 675 | if (LOG_DMA) logerror("Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); |
| 676 | if (DEBUG_SET(DMA_BREAK)) |
| 677 | debugger_break(machine); |
| 789 | 678 | |
| 790 | 679 | /* set the new control register */ |
| 791 | 680 | d->control = new_control; |
| r9685 | r9686 | |
| 793 | 682 | |
| 794 | 683 | static void drq_callback(running_machine *machine, int which) |
| 795 | 684 | { |
| 796 | | struct dma_state *dma = &i186.dma[which]; |
| 685 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 686 | struct dma_state *dma = &state->i186.dma[which]; |
| 797 | 687 | address_space *memory_space = cpu_get_address_space(machine->device(MAINCPU_TAG), ADDRESS_SPACE_PROGRAM); |
| 798 | | address_space *io_space = cpu_get_address_space(machine->device(MAINCPU_TAG), ADDRESS_SPACE_IO); |
| 688 | address_space *io_space = cpu_get_address_space(machine->device(MAINCPU_TAG), ADDRESS_SPACE_IO); |
| 799 | 689 | |
| 800 | 690 | address_space *src_space; |
| 801 | 691 | address_space *dest_space; |
| r9685 | r9686 | |
| 810 | 700 | if(!(dma->control & ST_STOP)) |
| 811 | 701 | { |
| 812 | 702 | logerror("%05X:ERROR! - drq%d with dma channel stopped\n", |
| 813 | | cpu_get_pc(machine->device(MAINCPU_TAG)), which); |
| 703 | cpu_get_pc(machine->device(MAINCPU_TAG)), which); |
| 814 | 704 | |
| 815 | 705 | return; |
| 816 | 706 | } |
| r9685 | r9686 | |
| 866 | 756 | if((dma->control & INTERRUPT_ON_ZERO) && (dma->count==0)) |
| 867 | 757 | { |
| 868 | 758 | if (LOG_DMA>1) logerror("DMA%d - requesting interrupt: count = %04X, source = %04X\n", which, dma->count, dma->source); |
| 869 | | i186.intr.request |= 0x04 << which; |
| 759 | state->i186.intr.request |= 0x04 << which; |
| 870 | 760 | update_interrupt_state(machine); |
| 871 | 761 | } |
| 872 | 762 | } |
| r9685 | r9686 | |
| 877 | 767 | /*-------------------------------------------------------------------------*/ |
| 878 | 768 | static void nimbus_cpu_init(running_machine *machine) |
| 879 | 769 | { |
| 770 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 771 | logerror("Machine reset\n"); |
| 880 | 772 | |
| 881 | | logerror("Machine reset\n"); |
| 882 | | |
| 883 | 773 | /* create timers here so they stick around */ |
| 884 | | i186.timer[0].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 885 | | i186.timer[1].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 886 | | i186.timer[2].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 887 | | i186.timer[0].time_timer = timer_alloc(machine, NULL, NULL); |
| 888 | | i186.timer[1].time_timer = timer_alloc(machine, NULL, NULL); |
| 889 | | i186.timer[2].time_timer = timer_alloc(machine, NULL, NULL); |
| 890 | | i186.dma[0].finish_timer = timer_alloc(machine, dma_timer_callback, NULL); |
| 891 | | i186.dma[1].finish_timer = timer_alloc(machine, dma_timer_callback, NULL); |
| 774 | state->i186.timer[0].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 775 | state->i186.timer[1].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 776 | state->i186.timer[2].int_timer = timer_alloc(machine, internal_timer_int, NULL); |
| 777 | state->i186.timer[0].time_timer = timer_alloc(machine, NULL, NULL); |
| 778 | state->i186.timer[1].time_timer = timer_alloc(machine, NULL, NULL); |
| 779 | state->i186.timer[2].time_timer = timer_alloc(machine, NULL, NULL); |
| 780 | state->i186.dma[0].finish_timer = timer_alloc(machine, dma_timer_callback, NULL); |
| 781 | state->i186.dma[1].finish_timer = timer_alloc(machine, dma_timer_callback, NULL); |
| 892 | 782 | } |
| 893 | 783 | |
| 894 | 784 | static void nimbus_cpu_reset(running_machine *machine) |
| 895 | 785 | { |
| 786 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 896 | 787 | /* reset the interrupt state */ |
| 897 | | i186.intr.priority_mask = 0x0007; |
| 898 | | i186.intr.timer = 0x000f; |
| 899 | | i186.intr.dma[0] = 0x000f; |
| 900 | | i186.intr.dma[1] = 0x000f; |
| 901 | | i186.intr.ext[0] = 0x000f; |
| 902 | | i186.intr.ext[1] = 0x000f; |
| 903 | | i186.intr.ext[2] = 0x000f; |
| 904 | | i186.intr.ext[3] = 0x000f; |
| 905 | | i186.intr.in_service = 0x0000; |
| 788 | state->i186.intr.priority_mask = 0x0007; |
| 789 | state->i186.intr.timer = 0x000f; |
| 790 | state->i186.intr.dma[0] = 0x000f; |
| 791 | state->i186.intr.dma[1] = 0x000f; |
| 792 | state->i186.intr.ext[0] = 0x000f; |
| 793 | state->i186.intr.ext[1] = 0x000f; |
| 794 | state->i186.intr.ext[2] = 0x000f; |
| 795 | state->i186.intr.ext[3] = 0x000f; |
| 796 | state->i186.intr.in_service = 0x0000; |
| 906 | 797 | |
| 907 | | /* External vectors by default to internal int 0/1 vectors */ |
| 908 | | i186.intr.ext_vector[0] = 0x000C; |
| 909 | | i186.intr.ext_vector[1] = 0x000D; |
| 798 | /* External vectors by default to internal int 0/1 vectors */ |
| 799 | state->i186.intr.ext_vector[0] = 0x000C; |
| 800 | state->i186.intr.ext_vector[1] = 0x000D; |
| 910 | 801 | |
| 911 | | i186.intr.pending = 0x0000; |
| 912 | | i186.intr.ack_mask = 0x0000; |
| 913 | | i186.intr.request = 0x0000; |
| 914 | | i186.intr.status = 0x0000; |
| 915 | | i186.intr.poll_status = 0x0000; |
| 802 | state->i186.intr.pending = 0x0000; |
| 803 | state->i186.intr.ack_mask = 0x0000; |
| 804 | state->i186.intr.request = 0x0000; |
| 805 | state->i186.intr.status = 0x0000; |
| 806 | state->i186.intr.poll_status = 0x0000; |
| 916 | 807 | |
| 917 | | logerror("CPU reset done\n"); |
| 808 | logerror("CPU reset done\n"); |
| 918 | 809 | } |
| 919 | 810 | |
| 920 | 811 | READ16_HANDLER( nimbus_i186_internal_port_r ) |
| 921 | 812 | { |
| 813 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 922 | 814 | int temp, which; |
| 923 | 815 | |
| 924 | 816 | switch (offset) |
| r9685 | r9686 | |
| 929 | 821 | |
| 930 | 822 | case 0x12: |
| 931 | 823 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt poll\n", cpu_get_pc(space->cpu)); |
| 932 | | if (i186.intr.poll_status & 0x8000) |
| 824 | if (state->i186.intr.poll_status & 0x8000) |
| 933 | 825 | int_callback(space->machine->device(MAINCPU_TAG), 0); |
| 934 | | return i186.intr.poll_status; |
| 826 | return state->i186.intr.poll_status; |
| 935 | 827 | |
| 936 | 828 | case 0x13: |
| 937 | 829 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt poll status\n", cpu_get_pc(space->cpu)); |
| 938 | | return i186.intr.poll_status; |
| 830 | return state->i186.intr.poll_status; |
| 939 | 831 | |
| 940 | 832 | case 0x14: |
| 941 | 833 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt mask\n", cpu_get_pc(space->cpu)); |
| 942 | | temp = (i186.intr.timer >> 3) & 0x01; |
| 943 | | temp |= (i186.intr.dma[0] >> 1) & 0x04; |
| 944 | | temp |= (i186.intr.dma[1] >> 0) & 0x08; |
| 945 | | temp |= (i186.intr.ext[0] << 1) & 0x10; |
| 946 | | temp |= (i186.intr.ext[1] << 2) & 0x20; |
| 947 | | temp |= (i186.intr.ext[2] << 3) & 0x40; |
| 948 | | temp |= (i186.intr.ext[3] << 4) & 0x80; |
| 834 | temp = (state->i186.intr.timer >> 3) & 0x01; |
| 835 | temp |= (state->i186.intr.dma[0] >> 1) & 0x04; |
| 836 | temp |= (state->i186.intr.dma[1] >> 0) & 0x08; |
| 837 | temp |= (state->i186.intr.ext[0] << 1) & 0x10; |
| 838 | temp |= (state->i186.intr.ext[1] << 2) & 0x20; |
| 839 | temp |= (state->i186.intr.ext[2] << 3) & 0x40; |
| 840 | temp |= (state->i186.intr.ext[3] << 4) & 0x80; |
| 949 | 841 | return temp; |
| 950 | 842 | |
| 951 | 843 | case 0x15: |
| 952 | 844 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt priority mask\n", cpu_get_pc(space->cpu)); |
| 953 | | return i186.intr.priority_mask; |
| 845 | return state->i186.intr.priority_mask; |
| 954 | 846 | |
| 955 | 847 | case 0x16: |
| 956 | 848 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt in-service\n", cpu_get_pc(space->cpu)); |
| 957 | | return i186.intr.in_service; |
| 849 | return state->i186.intr.in_service; |
| 958 | 850 | |
| 959 | 851 | case 0x17: |
| 960 | 852 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt request\n", cpu_get_pc(space->cpu)); |
| 961 | | temp = i186.intr.request & ~0x0001; |
| 962 | | if (i186.intr.status & 0x0007) |
| 853 | temp = state->i186.intr.request & ~0x0001; |
| 854 | if (state->i186.intr.status & 0x0007) |
| 963 | 855 | temp |= 1; |
| 964 | 856 | return temp; |
| 965 | 857 | |
| 966 | 858 | case 0x18: |
| 967 | 859 | if (LOG_PORTS) logerror("%05X:read 80186 interrupt status\n", cpu_get_pc(space->cpu)); |
| 968 | | return i186.intr.status; |
| 860 | return state->i186.intr.status; |
| 969 | 861 | |
| 970 | 862 | case 0x19: |
| 971 | 863 | if (LOG_PORTS) logerror("%05X:read 80186 timer interrupt control\n", cpu_get_pc(space->cpu)); |
| 972 | | return i186.intr.timer; |
| 864 | return state->i186.intr.timer; |
| 973 | 865 | |
| 974 | 866 | case 0x1a: |
| 975 | 867 | if (LOG_PORTS) logerror("%05X:read 80186 DMA 0 interrupt control\n", cpu_get_pc(space->cpu)); |
| 976 | | return i186.intr.dma[0]; |
| 868 | return state->i186.intr.dma[0]; |
| 977 | 869 | |
| 978 | 870 | case 0x1b: |
| 979 | 871 | if (LOG_PORTS) logerror("%05X:read 80186 DMA 1 interrupt control\n", cpu_get_pc(space->cpu)); |
| 980 | | return i186.intr.dma[1]; |
| 872 | return state->i186.intr.dma[1]; |
| 981 | 873 | |
| 982 | 874 | case 0x1c: |
| 983 | 875 | if (LOG_PORTS) logerror("%05X:read 80186 INT 0 interrupt control\n", cpu_get_pc(space->cpu)); |
| 984 | | return i186.intr.ext[0]; |
| 876 | return state->i186.intr.ext[0]; |
| 985 | 877 | |
| 986 | 878 | case 0x1d: |
| 987 | 879 | if (LOG_PORTS) logerror("%05X:read 80186 INT 1 interrupt control\n", cpu_get_pc(space->cpu)); |
| 988 | | return i186.intr.ext[1]; |
| 880 | return state->i186.intr.ext[1]; |
| 989 | 881 | |
| 990 | 882 | case 0x1e: |
| 991 | 883 | if (LOG_PORTS) logerror("%05X:read 80186 INT 2 interrupt control\n", cpu_get_pc(space->cpu)); |
| 992 | | return i186.intr.ext[2]; |
| 884 | return state->i186.intr.ext[2]; |
| 993 | 885 | |
| 994 | 886 | case 0x1f: |
| 995 | 887 | if (LOG_PORTS) logerror("%05X:read 80186 INT 3 interrupt control\n", cpu_get_pc(space->cpu)); |
| 996 | | return i186.intr.ext[3]; |
| 888 | return state->i186.intr.ext[3]; |
| 997 | 889 | |
| 998 | 890 | case 0x28: |
| 999 | 891 | case 0x2c: |
| r9685 | r9686 | |
| 1001 | 893 | if (LOG_PORTS) logerror("%05X:read 80186 Timer %d count\n", cpu_get_pc(space->cpu), (offset - 0x28) / 4); |
| 1002 | 894 | which = (offset - 0x28) / 4; |
| 1003 | 895 | if (!(offset & 1)) |
| 1004 | | internal_timer_sync(which); |
| 1005 | | return i186.timer[which].count; |
| 896 | internal_timer_sync(space->machine, which); |
| 897 | return state->i186.timer[which].count; |
| 1006 | 898 | |
| 1007 | 899 | case 0x29: |
| 1008 | 900 | case 0x2d: |
| 1009 | 901 | case 0x31: |
| 1010 | 902 | if (LOG_PORTS) logerror("%05X:read 80186 Timer %d max A\n", cpu_get_pc(space->cpu), (offset - 0x29) / 4); |
| 1011 | 903 | which = (offset - 0x29) / 4; |
| 1012 | | return i186.timer[which].maxA; |
| 904 | return state->i186.timer[which].maxA; |
| 1013 | 905 | |
| 1014 | 906 | case 0x2a: |
| 1015 | 907 | case 0x2e: |
| 1016 | 908 | logerror("%05X:read 80186 Timer %d max B\n", cpu_get_pc(space->cpu), (offset - 0x2a) / 4); |
| 1017 | 909 | which = (offset - 0x2a) / 4; |
| 1018 | | return i186.timer[which].maxB; |
| 910 | return state->i186.timer[which].maxB; |
| 1019 | 911 | |
| 1020 | 912 | case 0x2b: |
| 1021 | 913 | case 0x2f: |
| 1022 | 914 | case 0x33: |
| 1023 | 915 | if (LOG_PORTS) logerror("%05X:read 80186 Timer %d control\n", cpu_get_pc(space->cpu), (offset - 0x2b) / 4); |
| 1024 | 916 | which = (offset - 0x2b) / 4; |
| 1025 | | return i186.timer[which].control; |
| 917 | return state->i186.timer[which].control; |
| 1026 | 918 | |
| 1027 | 919 | case 0x50: |
| 1028 | 920 | if (LOG_PORTS) logerror("%05X:read 80186 upper chip select\n", cpu_get_pc(space->cpu)); |
| 1029 | | return i186.mem.upper; |
| 921 | return state->i186.mem.upper; |
| 1030 | 922 | |
| 1031 | 923 | case 0x51: |
| 1032 | 924 | if (LOG_PORTS) logerror("%05X:read 80186 lower chip select\n", cpu_get_pc(space->cpu)); |
| 1033 | | return i186.mem.lower; |
| 925 | return state->i186.mem.lower; |
| 1034 | 926 | |
| 1035 | 927 | case 0x52: |
| 1036 | 928 | if (LOG_PORTS) logerror("%05X:read 80186 peripheral chip select\n", cpu_get_pc(space->cpu)); |
| 1037 | | return i186.mem.peripheral; |
| 929 | return state->i186.mem.peripheral; |
| 1038 | 930 | |
| 1039 | 931 | case 0x53: |
| 1040 | 932 | if (LOG_PORTS) logerror("%05X:read 80186 middle chip select\n", cpu_get_pc(space->cpu)); |
| 1041 | | return i186.mem.middle; |
| 933 | return state->i186.mem.middle; |
| 1042 | 934 | |
| 1043 | 935 | case 0x54: |
| 1044 | 936 | if (LOG_PORTS) logerror("%05X:read 80186 middle P chip select\n", cpu_get_pc(space->cpu)); |
| 1045 | | return i186.mem.middle_size; |
| 937 | return state->i186.mem.middle_size; |
| 1046 | 938 | |
| 1047 | 939 | case 0x60: |
| 1048 | 940 | case 0x68: |
| 1049 | 941 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower source address\n", cpu_get_pc(space->cpu), (offset - 0x60) / 8); |
| 1050 | 942 | which = (offset - 0x60) / 8; |
| 1051 | | return i186.dma[which].source; |
| 943 | return state->i186.dma[which].source; |
| 1052 | 944 | |
| 1053 | 945 | case 0x61: |
| 1054 | 946 | case 0x69: |
| 1055 | 947 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper source address\n", cpu_get_pc(space->cpu), (offset - 0x61) / 8); |
| 1056 | 948 | which = (offset - 0x61) / 8; |
| 1057 | | return i186.dma[which].source >> 16; |
| 949 | return state->i186.dma[which].source >> 16; |
| 1058 | 950 | |
| 1059 | 951 | case 0x62: |
| 1060 | 952 | case 0x6a: |
| 1061 | 953 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower dest address\n", cpu_get_pc(space->cpu), (offset - 0x62) / 8); |
| 1062 | 954 | which = (offset - 0x62) / 8; |
| 1063 | | return i186.dma[which].dest; |
| 955 | return state->i186.dma[which].dest; |
| 1064 | 956 | |
| 1065 | 957 | case 0x63: |
| 1066 | 958 | case 0x6b: |
| 1067 | 959 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper dest address\n", cpu_get_pc(space->cpu), (offset - 0x63) / 8); |
| 1068 | 960 | which = (offset - 0x63) / 8; |
| 1069 | | return i186.dma[which].dest >> 16; |
| 961 | return state->i186.dma[which].dest >> 16; |
| 1070 | 962 | |
| 1071 | 963 | case 0x64: |
| 1072 | 964 | case 0x6c: |
| 1073 | 965 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d transfer count\n", cpu_get_pc(space->cpu), (offset - 0x64) / 8); |
| 1074 | 966 | which = (offset - 0x64) / 8; |
| 1075 | | return i186.dma[which].count; |
| 967 | return state->i186.dma[which].count; |
| 1076 | 968 | |
| 1077 | 969 | case 0x65: |
| 1078 | 970 | case 0x6d: |
| 1079 | 971 | if (LOG_PORTS) logerror("%05X:read 80186 DMA%d control\n", cpu_get_pc(space->cpu), (offset - 0x65) / 8); |
| 1080 | 972 | which = (offset - 0x65) / 8; |
| 1081 | | return i186.dma[which].control; |
| 973 | return state->i186.dma[which].control; |
| 1082 | 974 | |
| 1083 | 975 | default: |
| 1084 | 976 | logerror("%05X:read 80186 port %02X\n", cpu_get_pc(space->cpu), offset); |
| r9685 | r9686 | |
| 1095 | 987 | |
| 1096 | 988 | WRITE16_HANDLER( nimbus_i186_internal_port_w ) |
| 1097 | 989 | { |
| 990 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 1098 | 991 | int temp, which, data16 = data; |
| 1099 | 992 | |
| 1100 | 993 | switch (offset) |
| r9685 | r9686 | |
| 1115 | 1008 | |
| 1116 | 1009 | case 0x14: |
| 1117 | 1010 | if (LOG_PORTS) logerror("%05X:80186 interrupt mask = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1118 | | i186.intr.timer = (i186.intr.timer & ~0x08) | ((data16 << 3) & 0x08); |
| 1119 | | i186.intr.dma[0] = (i186.intr.dma[0] & ~0x08) | ((data16 << 1) & 0x08); |
| 1120 | | i186.intr.dma[1] = (i186.intr.dma[1] & ~0x08) | ((data16 << 0) & 0x08); |
| 1121 | | i186.intr.ext[0] = (i186.intr.ext[0] & ~0x08) | ((data16 >> 1) & 0x08); |
| 1122 | | i186.intr.ext[1] = (i186.intr.ext[1] & ~0x08) | ((data16 >> 2) & 0x08); |
| 1123 | | i186.intr.ext[2] = (i186.intr.ext[2] & ~0x08) | ((data16 >> 3) & 0x08); |
| 1124 | | i186.intr.ext[3] = (i186.intr.ext[3] & ~0x08) | ((data16 >> 4) & 0x08); |
| 1011 | state->i186.intr.timer = (state->i186.intr.timer & ~0x08) | ((data16 << 3) & 0x08); |
| 1012 | state->i186.intr.dma[0] = (state->i186.intr.dma[0] & ~0x08) | ((data16 << 1) & 0x08); |
| 1013 | state->i186.intr.dma[1] = (state->i186.intr.dma[1] & ~0x08) | ((data16 << 0) & 0x08); |
| 1014 | state->i186.intr.ext[0] = (state->i186.intr.ext[0] & ~0x08) | ((data16 >> 1) & 0x08); |
| 1015 | state->i186.intr.ext[1] = (state->i186.intr.ext[1] & ~0x08) | ((data16 >> 2) & 0x08); |
| 1016 | state->i186.intr.ext[2] = (state->i186.intr.ext[2] & ~0x08) | ((data16 >> 3) & 0x08); |
| 1017 | state->i186.intr.ext[3] = (state->i186.intr.ext[3] & ~0x08) | ((data16 >> 4) & 0x08); |
| 1125 | 1018 | update_interrupt_state(space->machine); |
| 1126 | 1019 | break; |
| 1127 | 1020 | |
| 1128 | 1021 | case 0x15: |
| 1129 | 1022 | if (LOG_PORTS) logerror("%05X:80186 interrupt priority mask = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1130 | | i186.intr.priority_mask = data16 & 0x0007; |
| 1023 | state->i186.intr.priority_mask = data16 & 0x0007; |
| 1131 | 1024 | update_interrupt_state(space->machine); |
| 1132 | 1025 | break; |
| 1133 | 1026 | |
| 1134 | 1027 | case 0x16: |
| 1135 | 1028 | if (LOG_PORTS) logerror("%05X:80186 interrupt in-service = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1136 | | i186.intr.in_service = data16 & 0x00ff; |
| 1029 | state->i186.intr.in_service = data16 & 0x00ff; |
| 1137 | 1030 | update_interrupt_state(space->machine); |
| 1138 | 1031 | break; |
| 1139 | 1032 | |
| 1140 | 1033 | case 0x17: |
| 1141 | 1034 | if (LOG_PORTS) logerror("%05X:80186 interrupt request = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1142 | | i186.intr.request = (i186.intr.request & ~0x00c0) | (data16 & 0x00c0); |
| 1035 | state->i186.intr.request = (state->i186.intr.request & ~0x00c0) | (data16 & 0x00c0); |
| 1143 | 1036 | update_interrupt_state(space->machine); |
| 1144 | 1037 | break; |
| 1145 | 1038 | |
| 1146 | 1039 | case 0x18: |
| 1147 | 1040 | if (LOG_PORTS) logerror("%05X:WARNING - wrote to 80186 interrupt status = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1148 | | i186.intr.status = (i186.intr.status & ~0x8007) | (data16 & 0x8007); |
| 1041 | state->i186.intr.status = (state->i186.intr.status & ~0x8007) | (data16 & 0x8007); |
| 1149 | 1042 | update_interrupt_state(space->machine); |
| 1150 | 1043 | break; |
| 1151 | 1044 | |
| 1152 | 1045 | case 0x19: |
| 1153 | 1046 | if (LOG_PORTS) logerror("%05X:80186 timer interrupt contol = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1154 | | i186.intr.timer = data16 & 0x000f; |
| 1047 | state->i186.intr.timer = data16 & 0x000f; |
| 1155 | 1048 | break; |
| 1156 | 1049 | |
| 1157 | 1050 | case 0x1a: |
| 1158 | 1051 | if (LOG_PORTS) logerror("%05X:80186 DMA 0 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1159 | | i186.intr.dma[0] = data16 & 0x000f; |
| 1052 | state->i186.intr.dma[0] = data16 & 0x000f; |
| 1160 | 1053 | break; |
| 1161 | 1054 | |
| 1162 | 1055 | case 0x1b: |
| 1163 | 1056 | if (LOG_PORTS) logerror("%05X:80186 DMA 1 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1164 | | i186.intr.dma[1] = data16 & 0x000f; |
| 1057 | state->i186.intr.dma[1] = data16 & 0x000f; |
| 1165 | 1058 | break; |
| 1166 | 1059 | |
| 1167 | 1060 | case 0x1c: |
| 1168 | 1061 | if (LOG_PORTS) logerror("%05X:80186 INT 0 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1169 | | i186.intr.ext[0] = data16 & 0x007f; |
| 1062 | state->i186.intr.ext[0] = data16 & 0x007f; |
| 1170 | 1063 | break; |
| 1171 | 1064 | |
| 1172 | 1065 | case 0x1d: |
| 1173 | 1066 | if (LOG_PORTS) logerror("%05X:80186 INT 1 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1174 | | i186.intr.ext[1] = data16 & 0x007f; |
| 1067 | state->i186.intr.ext[1] = data16 & 0x007f; |
| 1175 | 1068 | break; |
| 1176 | 1069 | |
| 1177 | 1070 | case 0x1e: |
| 1178 | 1071 | if (LOG_PORTS) logerror("%05X:80186 INT 2 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1179 | | i186.intr.ext[2] = data16 & 0x001f; |
| 1072 | state->i186.intr.ext[2] = data16 & 0x001f; |
| 1180 | 1073 | break; |
| 1181 | 1074 | |
| 1182 | 1075 | case 0x1f: |
| 1183 | 1076 | if (LOG_PORTS) logerror("%05X:80186 INT 3 interrupt control = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1184 | | i186.intr.ext[3] = data16 & 0x001f; |
| 1077 | state->i186.intr.ext[3] = data16 & 0x001f; |
| 1185 | 1078 | break; |
| 1186 | 1079 | |
| 1187 | 1080 | case 0x28: |
| r9685 | r9686 | |
| 1217 | 1110 | |
| 1218 | 1111 | case 0x50: |
| 1219 | 1112 | if (LOG_PORTS) logerror("%05X:80186 upper chip select = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1220 | | i186.mem.upper = data16 | 0xc038; |
| 1113 | state->i186.mem.upper = data16 | 0xc038; |
| 1221 | 1114 | break; |
| 1222 | 1115 | |
| 1223 | 1116 | case 0x51: |
| 1224 | 1117 | if (LOG_PORTS) logerror("%05X:80186 lower chip select = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1225 | | i186.mem.lower = (data16 & 0x3fff) | 0x0038; printf("%X",i186.mem.lower); |
| 1118 | state->i186.mem.lower = (data16 & 0x3fff) | 0x0038; printf("%X",state->i186.mem.lower); |
| 1226 | 1119 | break; |
| 1227 | 1120 | |
| 1228 | 1121 | case 0x52: |
| 1229 | 1122 | if (LOG_PORTS) logerror("%05X:80186 peripheral chip select = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1230 | | i186.mem.peripheral = data16 | 0x0038; |
| 1123 | state->i186.mem.peripheral = data16 | 0x0038; |
| 1231 | 1124 | break; |
| 1232 | 1125 | |
| 1233 | 1126 | case 0x53: |
| 1234 | 1127 | if (LOG_PORTS) logerror("%05X:80186 middle chip select = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1235 | | i186.mem.middle = data16 | 0x01f8; |
| 1128 | state->i186.mem.middle = data16 | 0x01f8; |
| 1236 | 1129 | break; |
| 1237 | 1130 | |
| 1238 | 1131 | case 0x54: |
| 1239 | 1132 | if (LOG_PORTS) logerror("%05X:80186 middle P chip select = %04X\n", cpu_get_pc(space->cpu), data16); |
| 1240 | | i186.mem.middle_size = data16 | 0x8038; |
| 1133 | state->i186.mem.middle_size = data16 | 0x8038; |
| 1241 | 1134 | |
| 1242 | 1135 | /* we need to do this at a time when the I86 context is swapped in */ |
| 1243 | 1136 | /* this register is generally set once at startup and never again, so it's a good */ |
| r9685 | r9686 | |
| 1249 | 1142 | case 0x68: |
| 1250 | 1143 | if (LOG_PORTS) logerror("%05X:80186 DMA%d lower source address = %04X\n", cpu_get_pc(space->cpu), (offset - 0x60) / 8, data16); |
| 1251 | 1144 | which = (offset - 0x60) / 8; |
| 1252 | | i186.dma[which].source = (i186.dma[which].source & ~0x0ffff) | (data16 & 0x0ffff); |
| 1145 | state->i186.dma[which].source = (state->i186.dma[which].source & ~0x0ffff) | (data16 & 0x0ffff); |
| 1253 | 1146 | break; |
| 1254 | 1147 | |
| 1255 | 1148 | case 0x61: |
| 1256 | 1149 | case 0x69: |
| 1257 | 1150 | if (LOG_PORTS) logerror("%05X:80186 DMA%d upper source address = %04X\n", cpu_get_pc(space->cpu), (offset - 0x61) / 8, data16); |
| 1258 | 1151 | which = (offset - 0x61) / 8; |
| 1259 | | i186.dma[which].source = (i186.dma[which].source & ~0xf0000) | ((data16 << 16) & 0xf0000); |
| 1152 | state->i186.dma[which].source = (state->i186.dma[which].source & ~0xf0000) | ((data16 << 16) & 0xf0000); |
| 1260 | 1153 | break; |
| 1261 | 1154 | |
| 1262 | 1155 | case 0x62: |
| 1263 | 1156 | case 0x6a: |
| 1264 | 1157 | if (LOG_PORTS) logerror("%05X:80186 DMA%d lower dest address = %04X\n", cpu_get_pc(space->cpu), (offset - 0x62) / 8, data16); |
| 1265 | 1158 | which = (offset - 0x62) / 8; |
| 1266 | | i186.dma[which].dest = (i186.dma[which].dest & ~0x0ffff) | (data16 & 0x0ffff); |
| 1159 | state->i186.dma[which].dest = (state->i186.dma[which].dest & ~0x0ffff) | (data16 & 0x0ffff); |
| 1267 | 1160 | break; |
| 1268 | 1161 | |
| 1269 | 1162 | case 0x63: |
| 1270 | 1163 | case 0x6b: |
| 1271 | 1164 | if (LOG_PORTS) logerror("%05X:80186 DMA%d upper dest address = %04X\n", cpu_get_pc(space->cpu), (offset - 0x63) / 8, data16); |
| 1272 | 1165 | which = (offset - 0x63) / 8; |
| 1273 | | i186.dma[which].dest = (i186.dma[which].dest & ~0xf0000) | ((data16 << 16) & 0xf0000); |
| 1166 | state->i186.dma[which].dest = (state->i186.dma[which].dest & ~0xf0000) | ((data16 << 16) & 0xf0000); |
| 1274 | 1167 | break; |
| 1275 | 1168 | |
| 1276 | 1169 | case 0x64: |
| 1277 | 1170 | case 0x6c: |
| 1278 | 1171 | if (LOG_PORTS) logerror("%05X:80186 DMA%d transfer count = %04X\n", cpu_get_pc(space->cpu), (offset - 0x64) / 8, data16); |
| 1279 | 1172 | which = (offset - 0x64) / 8; |
| 1280 | | i186.dma[which].count = data16; |
| 1173 | state->i186.dma[which].count = data16; |
| 1281 | 1174 | break; |
| 1282 | 1175 | |
| 1283 | 1176 | case 0x65: |
| r9685 | r9686 | |
| 1333 | 1226 | |
| 1334 | 1227 | MACHINE_START( nimbus ) |
| 1335 | 1228 | { |
| 1336 | | /* init cpu */ |
| 1337 | | nimbus_cpu_init(machine); |
| 1229 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1230 | /* init cpu */ |
| 1231 | nimbus_cpu_init(machine); |
| 1338 | 1232 | |
| 1339 | | keyboard.keyscan_timer=timer_alloc(machine, keyscan_callback, NULL); |
| 1340 | | nimbus_mouse.mouse_timer=timer_alloc(machine, mouse_callback, NULL); |
| 1233 | state->keyboard.keyscan_timer=timer_alloc(machine, keyscan_callback, NULL); |
| 1234 | state->nimbus_mouse.mouse_timer=timer_alloc(machine, mouse_callback, NULL); |
| 1341 | 1235 | |
| 1342 | 1236 | /* setup debug commands */ |
| 1343 | 1237 | if (machine->debug_flags & DEBUG_FLAG_ENABLED) |
| 1344 | 1238 | { |
| 1345 | 1239 | debug_console_register_command(machine, "nimbus_irq", CMDFLAG_NONE, 0, 0, 2, execute_debug_irq); |
| 1346 | | debug_console_register_command(machine, "nimbus_intmasks", CMDFLAG_NONE, 0, 0, 0, execute_debug_intmasks); |
| 1347 | | debug_console_register_command(machine, "nimbus_debug", CMDFLAG_NONE, 0, 0, 1, nimbus_debug); |
| 1240 | debug_console_register_command(machine, "nimbus_intmasks", CMDFLAG_NONE, 0, 0, 0, execute_debug_intmasks); |
| 1241 | debug_console_register_command(machine, "nimbus_debug", CMDFLAG_NONE, 0, 0, 1, nimbus_debug); |
| 1348 | 1242 | |
| 1349 | | /* set up the instruction hook */ |
| 1243 | /* set up the instruction hook */ |
| 1350 | 1244 | machine->device(MAINCPU_TAG)->debug()->set_instruction_hook(instruction_hook); |
| 1351 | | } |
| 1245 | } |
| 1352 | 1246 | |
| 1353 | | debug_machine=DECODE_BIOS; |
| 1247 | state->debug_machine=DECODE_BIOS; |
| 1354 | 1248 | } |
| 1355 | 1249 | |
| 1356 | 1250 | static void execute_debug_irq(running_machine *machine, int ref, int params, const char *param[]) |
| r9685 | r9686 | |
| 1375 | 1269 | |
| 1376 | 1270 | static void execute_debug_intmasks(running_machine *machine, int ref, int params, const char *param[]) |
| 1377 | 1271 | { |
| 1272 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1378 | 1273 | int IntNo; |
| 1379 | 1274 | |
| 1380 | | debug_console_printf(machine,"i186.intr.priority_mask=%4X\n",i186.intr.priority_mask); |
| 1275 | debug_console_printf(machine,"i186.intr.priority_mask=%4X\n",state->i186.intr.priority_mask); |
| 1381 | 1276 | for(IntNo=0; IntNo<4; IntNo++) |
| 1382 | 1277 | { |
| 1383 | | debug_console_printf(machine,"extInt%d mask=%4X\n",IntNo,i186.intr.ext[IntNo]); |
| 1278 | debug_console_printf(machine,"extInt%d mask=%4X\n",IntNo,state->i186.intr.ext[IntNo]); |
| 1384 | 1279 | } |
| 1385 | 1280 | |
| 1386 | | debug_console_printf(machine,"i186.intr.request = %04X\n",i186.intr.request); |
| 1387 | | debug_console_printf(machine,"i186.intr.ack_mask = %04X\n",i186.intr.ack_mask); |
| 1388 | | debug_console_printf(machine,"i186.intr.in_service= %04X\n",i186.intr.in_service); |
| 1281 | debug_console_printf(machine,"i186.intr.request = %04X\n",state->i186.intr.request); |
| 1282 | debug_console_printf(machine,"i186.intr.ack_mask = %04X\n",state->i186.intr.ack_mask); |
| 1283 | debug_console_printf(machine,"i186.intr.in_service= %04X\n",state->i186.intr.in_service); |
| 1389 | 1284 | } |
| 1390 | 1285 | |
| 1391 | 1286 | static void nimbus_debug(running_machine *machine, int ref, int params, const char *param[]) |
| 1392 | 1287 | { |
| 1288 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1393 | 1289 | if(params>0) |
| 1394 | 1290 | { |
| 1395 | | sscanf(param[0],"%d",&debug_machine); |
| 1291 | sscanf(param[0],"%d",&state->debug_machine); |
| 1396 | 1292 | } |
| 1397 | 1293 | else |
| 1398 | 1294 | { |
| 1399 | 1295 | debug_console_printf(machine,"Error usage : nimbus_debug <debuglevel>\n"); |
| 1400 | | debug_console_printf(machine,"Current debuglevel=%02X\n",debug_machine); |
| 1296 | debug_console_printf(machine,"Current debuglevel=%02X\n",state->debug_machine); |
| 1401 | 1297 | } |
| 1402 | 1298 | } |
| 1403 | 1299 | |
| r9685 | r9686 | |
| 1407 | 1303 | |
| 1408 | 1304 | static int instruction_hook(device_t &device, offs_t curpc) |
| 1409 | 1305 | { |
| 1306 | rmnimbus_state *state = device.machine->driver_data<rmnimbus_state>(); |
| 1410 | 1307 | address_space *space = cpu_get_address_space(&device, ADDRESS_SPACE_PROGRAM); |
| 1411 | 1308 | UINT8 *addr_ptr; |
| 1412 | 1309 | |
| r9685 | r9686 | |
| 1944 | 1841 | |
| 1945 | 1842 | static void nimbus_bank_memory(running_machine *machine) |
| 1946 | 1843 | { |
| 1844 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1947 | 1845 | address_space *space = cputag_get_address_space( machine, MAINCPU_TAG, ADDRESS_SPACE_PROGRAM ); |
| 1948 | | int ramsize = messram_get_size(machine->device("messram")); |
| 1846 | int ramsize = messram_get_size(machine->device("messram")); |
| 1949 | 1847 | int ramblock = 0; |
| 1950 | 1848 | int blockno; |
| 1951 | 1849 | char bank[10]; |
| r9685 | r9686 | |
| 1955 | 1853 | int map_blockno; |
| 1956 | 1854 | int block_ofs; |
| 1957 | 1855 | |
| 1958 | | UINT8 ramsel = (mcu_reg080 & 0x1F); |
| 1856 | UINT8 ramsel = (state->mcu_reg080 & 0x1F); |
| 1959 | 1857 | |
| 1960 | 1858 | // Invalid ramsel, return. |
| 1961 | 1859 | if((ramsel & 0x07)!=0x07) |
| r9685 | r9686 | |
| 1976 | 1874 | map_blocks[1] = (ramblocks[ramblock][1].blocksize==0) ? NULL : &ram[ramblocks[ramblock][1].blockbase*1024]; |
| 1977 | 1875 | map_blocks[2] = (ramblocks[ramblock][2].blocksize==0) ? NULL : &ram[ramblocks[ramblock][2].blockbase*1024]; |
| 1978 | 1876 | |
| 1979 | | //if(LOG_RAM) logerror("\n\nmcu_reg080=%02X, ramblock=%d, map_blocks[0]=%X, map_blocks[1]=%X, map_blocks[2]=%X\n",mcu_reg080,ramblock,(int)map_blocks[0],(int)map_blocks[1],(int)map_blocks[2]); |
| 1877 | //if(LOG_RAM) logerror("\n\nmcu_reg080=%02X, ramblock=%d, map_blocks[0]=%X, map_blocks[1]=%X, map_blocks[2]=%X\n",state->mcu_reg080,ramblock,(int)map_blocks[0],(int)map_blocks[1],(int)map_blocks[2]); |
| 1980 | 1878 | |
| 1981 | 1879 | for(blockno=0;blockno<8;blockno++) |
| 1982 | 1880 | { |
| r9685 | r9686 | |
| 2014 | 1912 | |
| 2015 | 1913 | READ8_HANDLER( nimbus_mcu_r ) |
| 2016 | 1914 | { |
| 2017 | | return mcu_reg080; |
| 1915 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 1916 | return state->mcu_reg080; |
| 2018 | 1917 | } |
| 2019 | 1918 | |
| 2020 | 1919 | WRITE8_HANDLER( nimbus_mcu_w ) |
| 2021 | 1920 | { |
| 2022 | | mcu_reg080=data; |
| 1921 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 1922 | state->mcu_reg080=data; |
| 2023 | 1923 | |
| 2024 | 1924 | nimbus_bank_memory(space->machine); |
| 2025 | 1925 | } |
| 2026 | 1926 | |
| 2027 | 1927 | static void memory_reset(running_machine *machine) |
| 2028 | 1928 | { |
| 2029 | | mcu_reg080=0x07; |
| 1929 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1930 | state->mcu_reg080=0x07; |
| 2030 | 1931 | nimbus_bank_memory(machine); |
| 2031 | 1932 | } |
| 2032 | 1933 | |
| 2033 | 1934 | READ16_HANDLER( nimbus_io_r ) |
| 2034 | 1935 | { |
| 1936 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2035 | 1937 | int pc=cpu_get_pc(space->cpu); |
| 2036 | 1938 | |
| 2037 | | logerror("Nimbus IOR at pc=%08X from %04X mask=%04X, data=%04X\n",pc,(offset*2)+0x30,mem_mask,IOPorts[offset]); |
| 1939 | logerror("Nimbus IOR at pc=%08X from %04X mask=%04X, data=%04X\n",pc,(offset*2)+0x30,mem_mask,state->IOPorts[offset]); |
| 2038 | 1940 | |
| 2039 | 1941 | switch (offset*2) |
| 2040 | 1942 | { |
| 2041 | | default : return IOPorts[offset]; |
| 1943 | default : return state->IOPorts[offset]; |
| 2042 | 1944 | } |
| 2043 | 1945 | return 0; |
| 2044 | 1946 | } |
| 2045 | 1947 | |
| 2046 | 1948 | WRITE16_HANDLER( nimbus_io_w ) |
| 2047 | 1949 | { |
| 1950 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2048 | 1951 | int pc=cpu_get_pc(space->cpu); |
| 2049 | 1952 | |
| 2050 | 1953 | logerror("Nimbus IOW at %08X write of %04X to %04X mask=%04X\n",pc,data,(offset*2)+0x30,mem_mask); |
| 2051 | 1954 | |
| 2052 | 1955 | switch (offset*2) |
| 2053 | 1956 | { |
| 2054 | | default : COMBINE_DATA(&IOPorts[offset]); break; |
| 1957 | default : COMBINE_DATA(&state->IOPorts[offset]); break; |
| 2055 | 1958 | } |
| 2056 | 1959 | } |
| 2057 | 1960 | |
| r9685 | r9686 | |
| 2063 | 1966 | |
| 2064 | 1967 | static void keyboard_reset(running_machine *machine) |
| 2065 | 1968 | { |
| 2066 | | memset(keyboard.keyrows,0xFF,NIMBUS_KEYROWS); |
| 1969 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1970 | memset(state->keyboard.keyrows,0xFF,NIMBUS_KEYROWS); |
| 2067 | 1971 | |
| 2068 | | // Setup timer to scan keyboard. |
| 2069 | | timer_adjust_periodic(keyboard.keyscan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(50)); |
| 1972 | // Setup timer to scan state->keyboard. |
| 1973 | timer_adjust_periodic(state->keyboard.keyscan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(50)); |
| 2070 | 1974 | } |
| 2071 | 1975 | |
| 2072 | | static void queue_scancode(UINT8 scancode) |
| 1976 | static void queue_scancode(running_machine *machine, UINT8 scancode) |
| 2073 | 1977 | { |
| 2074 | | keyboard.queue[keyboard.head] = scancode; |
| 2075 | | keyboard.head++; |
| 2076 | | keyboard.head %= ARRAY_LENGTH(keyboard.queue); |
| 1978 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 1979 | state->keyboard.queue[state->keyboard.head] = scancode; |
| 1980 | state->keyboard.head++; |
| 1981 | state->keyboard.head %= ARRAY_LENGTH(state->keyboard.queue); |
| 2077 | 1982 | } |
| 2078 | 1983 | |
| 2079 | | static int keyboard_queue_read(void) |
| 1984 | static int keyboard_queue_read(running_machine *machine) |
| 2080 | 1985 | { |
| 1986 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2081 | 1987 | int data; |
| 2082 | | if (keyboard.tail == keyboard.head) |
| 1988 | if (state->keyboard.tail == state->keyboard.head) |
| 2083 | 1989 | return -1; |
| 2084 | 1990 | |
| 2085 | | data = keyboard.queue[keyboard.tail]; |
| 1991 | data = state->keyboard.queue[state->keyboard.tail]; |
| 2086 | 1992 | |
| 2087 | 1993 | if (LOG_KEYBOARD) |
| 2088 | 1994 | logerror("keyboard_queue_read(): Keyboard Read 0x%02x\n",data); |
| 2089 | 1995 | |
| 2090 | | keyboard.tail++; |
| 2091 | | keyboard.tail %= ARRAY_LENGTH(keyboard.queue); |
| 1996 | state->keyboard.tail++; |
| 1997 | state->keyboard.tail %= ARRAY_LENGTH(state->keyboard.queue); |
| 2092 | 1998 | return data; |
| 2093 | 1999 | } |
| 2094 | 2000 | |
| 2095 | 2001 | static void scan_keyboard(running_machine *machine) |
| 2096 | 2002 | |
| 2097 | 2003 | { |
| 2004 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2098 | 2005 | UINT8 keyrow; |
| 2099 | 2006 | UINT8 row; |
| 2100 | 2007 | UINT8 bitno; |
| r9685 | r9686 | |
| 2111 | 2018 | |
| 2112 | 2019 | for(mask=0x80, bitno=7;mask>0;mask=mask>>1, bitno-=1) |
| 2113 | 2020 | { |
| 2114 | | if(!(keyrow & mask) && (keyboard.keyrows[row] & mask)) |
| 2021 | if(!(keyrow & mask) && (state->keyboard.keyrows[row] & mask)) |
| 2115 | 2022 | { |
| 2116 | 2023 | if (LOG_KEYBOARD) logerror("keypress %02X\n",(row<<3)+bitno); |
| 2117 | | queue_scancode((row<<3)+bitno); |
| 2024 | queue_scancode(machine, (row<<3)+bitno); |
| 2118 | 2025 | } |
| 2119 | 2026 | |
| 2120 | | if((keyrow & mask) && !(keyboard.keyrows[row] & mask)) |
| 2027 | if((keyrow & mask) && !(state->keyboard.keyrows[row] & mask)) |
| 2121 | 2028 | { |
| 2122 | 2029 | if (LOG_KEYBOARD) logerror("keyrelease %02X\n",0x80+(row<<3)+bitno); |
| 2123 | | queue_scancode(0x80+(row<<3)+bitno); |
| 2030 | queue_scancode(machine, 0x80+(row<<3)+bitno); |
| 2124 | 2031 | } |
| 2125 | 2032 | } |
| 2126 | 2033 | |
| 2127 | | keyboard.keyrows[row]=keyrow; |
| 2034 | state->keyboard.keyrows[row]=keyrow; |
| 2128 | 2035 | } |
| 2129 | 2036 | } |
| 2130 | 2037 | |
| r9685 | r9686 | |
| 2143 | 2050 | |
| 2144 | 2051 | static void sio_interrupt(running_device *device, int state) |
| 2145 | 2052 | { |
| 2053 | rmnimbus_state *drvstate = device->machine->driver_data<rmnimbus_state>(); |
| 2146 | 2054 | if(LOG_SIO) |
| 2147 | 2055 | logerror("SIO Interrupt state=%02X\n",state); |
| 2148 | 2056 | |
| 2149 | 2057 | // Don't re-trigger if already active ! |
| 2150 | | if(state!=sio_int_state) |
| 2058 | if(state!=drvstate->sio_int_state) |
| 2151 | 2059 | { |
| 2152 | | sio_int_state=state; |
| 2060 | drvstate->sio_int_state=state; |
| 2153 | 2061 | |
| 2154 | 2062 | if(state) |
| 2155 | 2063 | external_int(device->machine,0,EXTERNAL_INT_Z80SIO); |
| r9685 | r9686 | |
| 2171 | 2079 | |
| 2172 | 2080 | static int sio_serial_receive( running_device *device, int channel ) |
| 2173 | 2081 | { |
| 2174 | | if(channel==0) |
| 2082 | if(channel==0) |
| 2175 | 2083 | { |
| 2176 | | return keyboard_queue_read(); |
| 2084 | return keyboard_queue_read(device->machine); |
| 2177 | 2085 | } |
| 2178 | 2086 | else |
| 2179 | 2087 | return -1; |
| r9685 | r9686 | |
| 2183 | 2091 | |
| 2184 | 2092 | static void fdc_reset(running_machine *machine) |
| 2185 | 2093 | { |
| 2186 | | nimbus_drives.reg400=0; |
| 2187 | | nimbus_drives.reg410_in=0; |
| 2188 | | nimbus_drives.reg410_out=0; |
| 2189 | | nimbus_drives.int_ff=0; |
| 2094 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2095 | state->nimbus_drives.reg400=0; |
| 2096 | state->nimbus_drives.reg410_in=0; |
| 2097 | state->nimbus_drives.reg410_out=0; |
| 2098 | state->nimbus_drives.int_ff=0; |
| 2190 | 2099 | } |
| 2191 | 2100 | |
| 2192 | 2101 | static void set_disk_int(running_machine *machine, int state) |
| 2193 | 2102 | { |
| 2103 | rmnimbus_state *drvstate = machine->driver_data<rmnimbus_state>(); |
| 2194 | 2104 | if(LOG_DISK) |
| 2195 | 2105 | logerror("nimbus_drives_intrq = %d\n",state); |
| 2196 | 2106 | |
| 2197 | | if(iou_reg092 & DISK_INT_ENABLE) |
| 2107 | if(drvstate->iou_reg092 & DISK_INT_ENABLE) |
| 2198 | 2108 | { |
| 2199 | | nimbus_drives.int_ff=state; |
| 2109 | drvstate->nimbus_drives.int_ff=state; |
| 2200 | 2110 | |
| 2201 | 2111 | if(state) |
| 2202 | 2112 | external_int(machine,0,EXTERNAL_INT_DISK); |
| r9685 | r9686 | |
| 2210 | 2120 | |
| 2211 | 2121 | static WRITE_LINE_DEVICE_HANDLER( nimbus_fdc_drq_w ) |
| 2212 | 2122 | { |
| 2123 | rmnimbus_state *drvstate = device->machine->driver_data<rmnimbus_state>(); |
| 2213 | 2124 | |
| 2214 | 2125 | if(LOG_DISK) |
| 2215 | 2126 | logerror("nimbus_drives_drq_w(%d)\n", state); |
| 2216 | 2127 | |
| 2217 | | if(state && FDC_DRQ_ENABLED()) |
| 2128 | if(state && FDC_DRQ_ENABLED(drvstate)) |
| 2218 | 2129 | drq_callback(device->machine,1); |
| 2219 | 2130 | } |
| 2220 | 2131 | |
| r9685 | r9686 | |
| 2233 | 2144 | |
| 2234 | 2145 | READ8_HANDLER( nimbus_disk_r ) |
| 2235 | 2146 | { |
| 2147 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2236 | 2148 | int result = 0; |
| 2237 | 2149 | running_device *fdc = space->machine->device(FDC_TAG); |
| 2238 | | running_device *hdc = space->machine->device(SCSIBUS_TAG); |
| 2150 | running_device *hdc = space->machine->device(SCSIBUS_TAG); |
| 2239 | 2151 | |
| 2240 | | int pc=cpu_get_pc(space->cpu); |
| 2241 | | running_device *drive = space->machine->device(nimbus_wd17xx_interface.floppy_drive_tags[FDC_DRIVE()]); |
| 2152 | int pc=cpu_get_pc(space->cpu); |
| 2153 | running_device *drive = space->machine->device(nimbus_wd17xx_interface.floppy_drive_tags[FDC_DRIVE()]); |
| 2242 | 2154 | |
| 2243 | | switch(offset*2) |
| 2155 | switch(offset*2) |
| 2244 | 2156 | { |
| 2245 | 2157 | case 0x08 : |
| 2246 | 2158 | result = wd17xx_status_r(fdc, 0); |
| r9685 | r9686 | |
| 2255 | 2167 | case 0x0E : |
| 2256 | 2168 | result = wd17xx_data_r(fdc, 0); |
| 2257 | 2169 | break; |
| 2258 | | case 0x10 : |
| 2259 | | nimbus_drives.reg410_in &= ~FDC_BITS_410; |
| 2260 | | nimbus_drives.reg410_in |= (FDC_MOTOR() ? FDC_MOTOR_MASKI : 0x00); |
| 2261 | | nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_INDEX) ? 0x00 : FDC_INDEX_MASK); |
| 2262 | | nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_READY) ? FDC_READY_MASK : 0x00); |
| 2170 | case 0x10 : |
| 2171 | state->nimbus_drives.reg410_in &= ~FDC_BITS_410; |
| 2172 | state->nimbus_drives.reg410_in |= (FDC_MOTOR() ? FDC_MOTOR_MASKI : 0x00); |
| 2173 | state->nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_INDEX) ? 0x00 : FDC_INDEX_MASK); |
| 2174 | state->nimbus_drives.reg410_in |= (floppy_drive_get_flag_state(drive, FLOPPY_DRIVE_READY) ? FDC_READY_MASK : 0x00); |
| 2263 | 2175 | |
| 2264 | | // Flip inverted bits |
| 2265 | | result=nimbus_drives.reg410_in ^ INV_BITS_410; |
| 2266 | | break; |
| 2267 | | case 0x18 : |
| 2268 | | result = scsi_data_r(hdc); |
| 2269 | | hdc_post_rw(space->machine); |
| 2176 | // Flip inverted bits |
| 2177 | result=state->nimbus_drives.reg410_in ^ INV_BITS_410; |
| 2178 | break; |
| 2179 | case 0x18 : |
| 2180 | result = scsi_data_r(hdc); |
| 2181 | hdc_post_rw(space->machine); |
| 2270 | 2182 | default: |
| 2271 | 2183 | break; |
| 2272 | 2184 | } |
| 2273 | 2185 | |
| 2274 | | if(LOG_DISK_FDD && ((offset*2)<=0x10)) |
| 2275 | | logerror("Nimbus FDCR at pc=%08X from %04X data=%02X\n",pc,(offset*2)+0x400,result); |
| 2186 | if(LOG_DISK_FDD && ((offset*2)<=0x10)) |
| 2187 | logerror("Nimbus FDCR at pc=%08X from %04X data=%02X\n",pc,(offset*2)+0x400,result); |
| 2276 | 2188 | |
| 2277 | | if((LOG_DISK_HDD) && ((offset*2)>=0x10)) |
| 2278 | | logerror("Nimbus HDCR at pc=%08X from %04X data=%02X\n",pc,(offset*2)+0x400,result); |
| 2189 | if((LOG_DISK_HDD) && ((offset*2)>=0x10)) |
| 2190 | logerror("Nimbus HDCR at pc=%08X from %04X data=%02X\n",pc,(offset*2)+0x400,result); |
| 2279 | 2191 | |
| 2280 | | |
| 2281 | 2192 | return result; |
| 2282 | 2193 | } |
| 2283 | 2194 | |
| r9685 | r9686 | |
| 2302 | 2213 | |
| 2303 | 2214 | WRITE8_HANDLER( nimbus_disk_w ) |
| 2304 | 2215 | { |
| 2216 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2305 | 2217 | running_device *fdc = space->machine->device(FDC_TAG); |
| 2306 | 2218 | running_device *hdc = space->machine->device(SCSIBUS_TAG); |
| 2307 | 2219 | int pc=cpu_get_pc(space->cpu); |
| 2308 | | UINT8 reg400_old = nimbus_drives.reg400; |
| 2220 | UINT8 reg400_old = state->nimbus_drives.reg400; |
| 2309 | 2221 | |
| 2310 | 2222 | if(LOG_DISK_FDD && ((offset*2)<=0x10)) |
| 2311 | 2223 | logerror("Nimbus FDCW at %05X write of %02X to %04X\n",pc,data,(offset*2)+0x400); |
| r9685 | r9686 | |
| 2316 | 2228 | switch(offset*2) |
| 2317 | 2229 | { |
| 2318 | 2230 | case 0x00 : |
| 2319 | | nimbus_drives.reg400=data; |
| 2231 | state->nimbus_drives.reg400=data; |
| 2320 | 2232 | |
| 2321 | 2233 | wd17xx_set_drive(fdc,FDC_DRIVE()); |
| 2322 | 2234 | wd17xx_set_side(fdc, FDC_SIDE()); |
| r9685 | r9686 | |
| 2354 | 2266 | |
| 2355 | 2267 | static void hdc_reset(running_machine *machine) |
| 2356 | 2268 | { |
| 2269 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2357 | 2270 | running_device *hdc = machine->device(SCSIBUS_TAG); |
| 2358 | 2271 | |
| 2359 | 2272 | init_scsibus(hdc); |
| 2360 | 2273 | |
| 2361 | | nimbus_drives.reg410_in=0; |
| 2362 | | nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_REQ) ? HDC_REQ_MASK : 0); |
| 2363 | | nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_CD) ? HDC_CD_MASK : 0); |
| 2364 | | nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_IO) ? HDC_IO_MASK : 0); |
| 2365 | | nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_BSY) ? HDC_BSY_MASK : 0); |
| 2366 | | nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_MSG) ? HDC_MSG_MASK : 0); |
| 2274 | state->nimbus_drives.reg410_in=0; |
| 2275 | state->nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_REQ) ? HDC_REQ_MASK : 0); |
| 2276 | state->nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_CD) ? HDC_CD_MASK : 0); |
| 2277 | state->nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_IO) ? HDC_IO_MASK : 0); |
| 2278 | state->nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_BSY) ? HDC_BSY_MASK : 0); |
| 2279 | state->nimbus_drives.reg410_in |= (get_scsi_line(hdc,SCSI_LINE_MSG) ? HDC_MSG_MASK : 0); |
| 2367 | 2280 | |
| 2368 | | nimbus_drives.drq_ff=0; |
| 2281 | state->nimbus_drives.drq_ff=0; |
| 2369 | 2282 | } |
| 2370 | 2283 | |
| 2371 | 2284 | static void hdc_ctrl_write(running_machine *machine, UINT8 data) |
| 2372 | 2285 | { |
| 2286 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2373 | 2287 | running_device *hdc = machine->device(SCSIBUS_TAG); |
| 2374 | 2288 | |
| 2375 | 2289 | // If we enable the HDC interupt, and an interrupt is pending, go deal with it. |
| 2376 | | if(((data & HDC_IRQ_MASK) && (~nimbus_drives.reg410_out & HDC_IRQ_MASK)) && |
| 2377 | | ((~nimbus_drives.reg410_in & HDC_INT_TRIGGER)==HDC_INT_TRIGGER)) |
| 2290 | if(((data & HDC_IRQ_MASK) && (~state->nimbus_drives.reg410_out & HDC_IRQ_MASK)) && |
| 2291 | ((~state->nimbus_drives.reg410_in & HDC_INT_TRIGGER)==HDC_INT_TRIGGER)) |
| 2378 | 2292 | set_disk_int(machine,1); |
| 2379 | 2293 | |
| 2380 | | nimbus_drives.reg410_out=data; |
| 2294 | state->nimbus_drives.reg410_out=data; |
| 2381 | 2295 | |
| 2382 | 2296 | set_scsi_line(hdc, SCSI_LINE_RESET, (data & HDC_RESET_MASK) ? 0 : 1); |
| 2383 | 2297 | set_scsi_line(hdc, SCSI_LINE_SEL, (data & HDC_SEL_MASK) ? 0 : 1); |
| r9685 | r9686 | |
| 2385 | 2299 | |
| 2386 | 2300 | static void hdc_post_rw(running_machine *machine) |
| 2387 | 2301 | { |
| 2302 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2388 | 2303 | running_device *hdc = machine->device(SCSIBUS_TAG); |
| 2389 | 2304 | |
| 2390 | | if((nimbus_drives.reg410_in & HDC_REQ_MASK)==0) |
| 2305 | if((state->nimbus_drives.reg410_in & HDC_REQ_MASK)==0) |
| 2391 | 2306 | set_scsi_line(hdc,SCSI_LINE_ACK,0); |
| 2392 | 2307 | |
| 2393 | | nimbus_drives.drq_ff=0; |
| 2308 | state->nimbus_drives.drq_ff=0; |
| 2394 | 2309 | } |
| 2395 | 2310 | |
| 2396 | 2311 | static void hdc_drq(running_machine *machine) |
| 2397 | 2312 | { |
| 2398 | | if(HDC_DRQ_ENABLED() && nimbus_drives.drq_ff) |
| 2313 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2314 | if(HDC_DRQ_ENABLED() && state->nimbus_drives.drq_ff) |
| 2399 | 2315 | { |
| 2400 | 2316 | drq_callback(machine,1); |
| 2401 | 2317 | } |
| r9685 | r9686 | |
| 2403 | 2319 | |
| 2404 | 2320 | void nimbus_scsi_linechange(running_device *device, UINT8 line, UINT8 state) |
| 2405 | 2321 | { |
| 2322 | rmnimbus_state *drvstate = device->machine->driver_data<rmnimbus_state>(); |
| 2406 | 2323 | UINT8 mask = 0; |
| 2407 | 2324 | UINT8 last = 0; |
| 2408 | 2325 | |
| r9685 | r9686 | |
| 2415 | 2332 | case SCSI_LINE_MSG : mask=HDC_MSG_MASK; break; |
| 2416 | 2333 | } |
| 2417 | 2334 | |
| 2418 | | last=nimbus_drives.reg410_in & mask; |
| 2335 | last=drvstate->nimbus_drives.reg410_in & mask; |
| 2419 | 2336 | |
| 2420 | 2337 | if(state) |
| 2421 | | nimbus_drives.reg410_in|=mask; |
| 2338 | drvstate->nimbus_drives.reg410_in|=mask; |
| 2422 | 2339 | else |
| 2423 | | nimbus_drives.reg410_in&=~mask; |
| 2340 | drvstate->nimbus_drives.reg410_in&=~mask; |
| 2424 | 2341 | |
| 2425 | 2342 | |
| 2426 | | if(HDC_IRQ_ENABLED() && ((~nimbus_drives.reg410_in & HDC_INT_TRIGGER)==HDC_INT_TRIGGER)) |
| 2343 | if(HDC_IRQ_ENABLED(drvstate) && ((~drvstate->nimbus_drives.reg410_in & HDC_INT_TRIGGER)==HDC_INT_TRIGGER)) |
| 2427 | 2344 | set_disk_int(device->machine,1); |
| 2428 | 2345 | else |
| 2429 | 2346 | set_disk_int(device->machine,0); |
| r9685 | r9686 | |
| 2432 | 2349 | { |
| 2433 | 2350 | if (state==0) |
| 2434 | 2351 | { |
| 2435 | | if(((nimbus_drives.reg410_in & HDC_CD_MASK)==HDC_CD_MASK) && (last!=0)) |
| 2352 | if(((drvstate->nimbus_drives.reg410_in & HDC_CD_MASK)==HDC_CD_MASK) && (last!=0)) |
| 2436 | 2353 | { |
| 2437 | | nimbus_drives.drq_ff=1; |
| 2354 | drvstate->nimbus_drives.drq_ff=1; |
| 2438 | 2355 | hdc_drq(device->machine); |
| 2439 | 2356 | } |
| 2440 | 2357 | } |
| r9685 | r9686 | |
| 2447 | 2364 | |
| 2448 | 2365 | static void pc8031_reset(running_machine *machine) |
| 2449 | 2366 | { |
| 2367 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2450 | 2368 | running_device *er59256 = machine->device(ER59256_TAG); |
| 2451 | 2369 | |
| 2452 | 2370 | logerror("peripheral controler reset\n"); |
| 2453 | 2371 | |
| 2454 | | memset(&ipc_interface,0,sizeof(ipc_interface)); |
| 2372 | memset(&state->ipc_interface,0,sizeof(state->ipc_interface)); |
| 2455 | 2373 | |
| 2456 | 2374 | if(!er59256_data_loaded(er59256)) |
| 2457 | 2375 | er59256_preload_rom(er59256,def_config,ARRAY_LENGTH(def_config)); |
| r9685 | r9686 | |
| 2461 | 2379 | #if 0 |
| 2462 | 2380 | static void ipc_dumpregs() |
| 2463 | 2381 | { |
| 2382 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2464 | 2383 | logerror("in_data=%02X, in_status=%02X, out_data=%02X, out_status=%02X\n", |
| 2465 | | ipc_interface.ipc_in, ipc_interface.status_in, |
| 2466 | | ipc_interface.ipc_out, ipc_interface.status_out); |
| 2384 | state->ipc_interface.ipc_in, state->ipc_interface.status_in, |
| 2385 | state->ipc_interface.ipc_out, state->ipc_interface.status_out); |
| 2467 | 2386 | |
| 2468 | 2387 | } |
| 2469 | 2388 | #endif |
| 2470 | 2389 | |
| 2471 | 2390 | READ8_HANDLER( nimbus_pc8031_r ) |
| 2472 | 2391 | { |
| 2392 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2473 | 2393 | int pc=cpu_get_pc(space->cpu); |
| 2474 | 2394 | UINT8 result; |
| 2475 | 2395 | |
| 2476 | 2396 | switch(offset*2) |
| 2477 | 2397 | { |
| 2478 | | case 0x00 : result=ipc_interface.ipc_out; |
| 2479 | | ipc_interface.status_in &= ~IPC_IN_READ_PEND; |
| 2480 | | ipc_interface.status_out &= ~IPC_OUT_BYTE_AVAIL; |
| 2398 | case 0x00 : result=state->ipc_interface.ipc_out; |
| 2399 | state->ipc_interface.status_in &= ~IPC_IN_READ_PEND; |
| 2400 | state->ipc_interface.status_out &= ~IPC_OUT_BYTE_AVAIL; |
| 2481 | 2401 | break; |
| 2482 | 2402 | |
| 2483 | | case 0x02 : result=ipc_interface.status_out; |
| 2403 | case 0x02 : result=state->ipc_interface.status_out; |
| 2484 | 2404 | break; |
| 2485 | 2405 | |
| 2486 | 2406 | default : result=0; break; |
| r9685 | r9686 | |
| 2494 | 2414 | |
| 2495 | 2415 | WRITE8_HANDLER( nimbus_pc8031_w ) |
| 2496 | 2416 | { |
| 2417 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2497 | 2418 | int pc=cpu_get_pc(space->cpu); |
| 2498 | 2419 | |
| 2499 | 2420 | switch(offset*2) |
| 2500 | 2421 | { |
| 2501 | | case 0x00 : ipc_interface.ipc_in=data; |
| 2502 | | ipc_interface.status_in |= IPC_IN_BYTE_AVAIL; |
| 2503 | | ipc_interface.status_in &= ~IPC_IN_ADDR; |
| 2504 | | ipc_interface.status_out |= IPC_OUT_READ_PEND; |
| 2422 | case 0x00 : state->ipc_interface.ipc_in=data; |
| 2423 | state->ipc_interface.status_in |= IPC_IN_BYTE_AVAIL; |
| 2424 | state->ipc_interface.status_in &= ~IPC_IN_ADDR; |
| 2425 | state->ipc_interface.status_out |= IPC_OUT_READ_PEND; |
| 2505 | 2426 | break; |
| 2506 | 2427 | |
| 2507 | | case 0x02 : ipc_interface.ipc_in=data; |
| 2508 | | ipc_interface.status_in |= IPC_IN_BYTE_AVAIL; |
| 2509 | | ipc_interface.status_in |= IPC_IN_ADDR; |
| 2510 | | ipc_interface.status_out |= IPC_OUT_READ_PEND; |
| 2428 | case 0x02 : state->ipc_interface.ipc_in=data; |
| 2429 | state->ipc_interface.status_in |= IPC_IN_BYTE_AVAIL; |
| 2430 | state->ipc_interface.status_in |= IPC_IN_ADDR; |
| 2431 | state->ipc_interface.status_out |= IPC_OUT_READ_PEND; |
| 2511 | 2432 | break; |
| 2512 | 2433 | } |
| 2513 | 2434 | |
| r9685 | r9686 | |
| 2520 | 2441 | |
| 2521 | 2442 | READ8_HANDLER( nimbus_pc8031_iou_r ) |
| 2522 | 2443 | { |
| 2444 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2523 | 2445 | int pc=cpu_get_pc(space->cpu); |
| 2524 | 2446 | UINT8 result = 0; |
| 2525 | 2447 | |
| 2526 | 2448 | switch (offset & 0x01) |
| 2527 | 2449 | { |
| 2528 | | case 0x00 : result=ipc_interface.ipc_in; |
| 2529 | | ipc_interface.status_out &= ~IPC_OUT_READ_PEND; |
| 2530 | | ipc_interface.status_in &= ~IPC_IN_BYTE_AVAIL; |
| 2450 | case 0x00 : result=state->ipc_interface.ipc_in; |
| 2451 | state->ipc_interface.status_out &= ~IPC_OUT_READ_PEND; |
| 2452 | state->ipc_interface.status_in &= ~IPC_IN_BYTE_AVAIL; |
| 2531 | 2453 | break; |
| 2532 | 2454 | |
| 2533 | | case 0x01 : result=ipc_interface.status_in; |
| 2455 | case 0x01 : result=state->ipc_interface.status_in; |
| 2534 | 2456 | break; |
| 2535 | 2457 | } |
| 2536 | 2458 | |
| 2537 | | if(((offset==2) || (offset==3)) && (iou_reg092 & PC8031_INT_ENABLE)) |
| 2459 | if(((offset==2) || (offset==3)) && (state->iou_reg092 & PC8031_INT_ENABLE)) |
| 2538 | 2460 | external_int(space->machine,0,EXTERNAL_INT_PC8031_8C); |
| 2539 | 2461 | |
| 2540 | 2462 | if(LOG_PC8031) |
| r9685 | r9686 | |
| 2545 | 2467 | |
| 2546 | 2468 | WRITE8_HANDLER( nimbus_pc8031_iou_w ) |
| 2547 | 2469 | { |
| 2470 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2548 | 2471 | int pc=cpu_get_pc(space->cpu); |
| 2549 | 2472 | |
| 2550 | 2473 | if(LOG_PC8031) |
| r9685 | r9686 | |
| 2552 | 2475 | |
| 2553 | 2476 | switch(offset & 0x03) |
| 2554 | 2477 | { |
| 2555 | | case 0x00 : ipc_interface.ipc_out=data; |
| 2556 | | ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2557 | | ipc_interface.status_out &= ~IPC_OUT_ADDR; |
| 2558 | | ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2478 | case 0x00 : state->ipc_interface.ipc_out=data; |
| 2479 | state->ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2480 | state->ipc_interface.status_out &= ~IPC_OUT_ADDR; |
| 2481 | state->ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2559 | 2482 | break; |
| 2560 | 2483 | |
| 2561 | | case 0x01 : ipc_interface.ipc_out=data; |
| 2562 | | ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2563 | | ipc_interface.status_out |= IPC_OUT_ADDR; |
| 2564 | | ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2484 | case 0x01 : state->ipc_interface.ipc_out=data; |
| 2485 | state->ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2486 | state->ipc_interface.status_out |= IPC_OUT_ADDR; |
| 2487 | state->ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2565 | 2488 | break; |
| 2566 | 2489 | |
| 2567 | | case 0x02 : ipc_interface.ipc_out=data; |
| 2568 | | ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2569 | | ipc_interface.status_out &= ~IPC_OUT_ADDR; |
| 2570 | | ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2571 | | if(iou_reg092 & PC8031_INT_ENABLE) |
| 2490 | case 0x02 : state->ipc_interface.ipc_out=data; |
| 2491 | state->ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2492 | state->ipc_interface.status_out &= ~IPC_OUT_ADDR; |
| 2493 | state->ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2494 | if(state->iou_reg092 & PC8031_INT_ENABLE) |
| 2572 | 2495 | external_int(space->machine,0,EXTERNAL_INT_PC8031_8F); |
| 2573 | 2496 | break; |
| 2574 | 2497 | |
| 2575 | | case 0x03 : ipc_interface.ipc_out=data; |
| 2576 | | //ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2577 | | ipc_interface.status_out |= IPC_OUT_ADDR; |
| 2578 | | ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2579 | | if(iou_reg092 & PC8031_INT_ENABLE) |
| 2498 | case 0x03 : state->ipc_interface.ipc_out=data; |
| 2499 | //state->ipc_interface.status_out |= IPC_OUT_BYTE_AVAIL; |
| 2500 | state->ipc_interface.status_out |= IPC_OUT_ADDR; |
| 2501 | state->ipc_interface.status_in |= IPC_IN_READ_PEND; |
| 2502 | if(state->iou_reg092 & PC8031_INT_ENABLE) |
| 2580 | 2503 | external_int(space->machine,0,EXTERNAL_INT_PC8031_8E); |
| 2581 | 2504 | break; |
| 2582 | 2505 | } |
| r9685 | r9686 | |
| 2618 | 2541 | /* IO Unit */ |
| 2619 | 2542 | READ8_HANDLER( nimbus_iou_r ) |
| 2620 | 2543 | { |
| 2544 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2621 | 2545 | int pc=cpu_get_pc(space->cpu); |
| 2622 | 2546 | UINT8 result=0; |
| 2623 | 2547 | |
| 2624 | 2548 | if(offset==0) |
| 2625 | 2549 | { |
| 2626 | | result=iou_reg092; |
| 2550 | result=state->iou_reg092; |
| 2627 | 2551 | } |
| 2628 | 2552 | |
| 2629 | 2553 | if(LOG_IOU) |
| r9685 | r9686 | |
| 2634 | 2558 | |
| 2635 | 2559 | WRITE8_HANDLER( nimbus_iou_w ) |
| 2636 | 2560 | { |
| 2561 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2637 | 2562 | int pc=cpu_get_pc(space->cpu); |
| 2638 | 2563 | running_device *msm5205 = space->machine->device(MSM5205_TAG); |
| 2639 | 2564 | |
| r9685 | r9686 | |
| 2642 | 2567 | |
| 2643 | 2568 | if(offset==0) |
| 2644 | 2569 | { |
| 2645 | | iou_reg092=data; |
| 2570 | state->iou_reg092=data; |
| 2646 | 2571 | msm5205_reset_w(msm5205, (data & MSM5205_INT_ENABLE) ? 0 : 1); |
| 2647 | 2572 | } |
| 2648 | 2573 | } |
| 2649 | 2574 | |
| 2650 | 2575 | static void iou_reset(running_machine *machine) |
| 2651 | 2576 | { |
| 2652 | | iou_reg092=0x00; |
| 2577 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2578 | state->iou_reg092=0x00; |
| 2653 | 2579 | } |
| 2654 | 2580 | |
| 2655 | 2581 | /* |
| r9685 | r9686 | |
| 2668 | 2594 | |
| 2669 | 2595 | static void sound_reset(running_machine *machine) |
| 2670 | 2596 | { |
| 2597 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 2671 | 2598 | //running_device *ay8910 = machine->device(AY8910_TAG); |
| 2672 | 2599 | running_device *msm5205 = machine->device(MSM5205_TAG); |
| 2673 | 2600 | |
| 2674 | 2601 | //ay8910_reset_ym(ay8910); |
| 2675 | 2602 | msm5205_reset_w(msm5205, 1); |
| 2676 | 2603 | |
| 2677 | | last_playmode=MSM5205_S48_4B; |
| 2678 | | msm5205_playmode_w(msm5205,last_playmode); |
| 2604 | state->last_playmode=MSM5205_S48_4B; |
| 2605 | msm5205_playmode_w(msm5205,state->last_playmode); |
| 2679 | 2606 | |
| 2680 | | ay8910_a=0; |
| 2607 | state->ay8910_a=0; |
| 2681 | 2608 | } |
| 2682 | 2609 | |
| 2683 | 2610 | READ8_HANDLER( nimbus_sound_ay8910_r ) |
| r9685 | r9686 | |
| 2709 | 2636 | |
| 2710 | 2637 | WRITE8_HANDLER( nimbus_sound_ay8910_porta_w ) |
| 2711 | 2638 | { |
| 2639 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2712 | 2640 | running_device *msm5205 = space->machine->device(MSM5205_TAG); |
| 2713 | 2641 | |
| 2714 | 2642 | msm5205_data_w(msm5205, data); |
| 2715 | 2643 | |
| 2716 | 2644 | // Mouse code needs a copy of this. |
| 2717 | | ay8910_a=data; |
| 2645 | state->ay8910_a=data; |
| 2718 | 2646 | } |
| 2719 | 2647 | |
| 2720 | 2648 | WRITE8_HANDLER( nimbus_sound_ay8910_portb_w ) |
| 2721 | 2649 | { |
| 2650 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 2722 | 2651 | running_device *msm5205 = space->machine->device(MSM5205_TAG); |
| 2723 | 2652 | |
| 2724 | | if((data & 0x07)!=last_playmode) |
| 2653 | if((data & 0x07)!=state->last_playmode) |
| 2725 | 2654 | { |
| 2726 | | last_playmode=(data & 0x07); |
| 2727 | | msm5205_playmode_w(msm5205, last_playmode); |
| 2655 | state->last_playmode=(data & 0x07); |
| 2656 | msm5205_playmode_w(msm5205, state->last_playmode); |
| 2728 | 2657 | } |
| 2729 | 2658 | } |
| 2730 | 2659 | |
| 2731 | 2660 | void nimbus_msm5205_vck(running_device *device) |
| 2732 | 2661 | { |
| 2733 | | if(iou_reg092 & MSM5205_INT_ENABLE) |
| 2662 | rmnimbus_state *state = device->machine->driver_data<rmnimbus_state>(); |
| 2663 | if(state->iou_reg092 & MSM5205_INT_ENABLE) |
| 2734 | 2664 | external_int(device->machine,0,EXTERNAL_INT_MSM5205); |
| 2735 | 2665 | } |
| 2736 | 2666 | |
| r9685 | r9686 | |
| 2741 | 2671 | |
| 2742 | 2672 | static void mouse_js_reset(running_machine *machine) |
| 2743 | 2673 | { |
| 2744 | | _mouse_joy_state *state = &nimbus_mouse; |
| 2674 | rmnimbus_state *drvstate = machine->driver_data<rmnimbus_state>(); |
| 2675 | _mouse_joy_state *state = &drvstate->nimbus_mouse; |
| 2745 | 2676 | |
| 2746 | 2677 | state->mouse_px=0; |
| 2747 | 2678 | state->mouse_py=0; |
| r9685 | r9686 | |
| 2755 | 2686 | state->reg0a4=0xC0; |
| 2756 | 2687 | |
| 2757 | 2688 | // Setup timer to poll the mouse |
| 2758 | | timer_adjust_periodic(nimbus_mouse.mouse_timer, attotime_zero, 0, ATTOTIME_IN_HZ(1000)); |
| 2689 | timer_adjust_periodic(state->mouse_timer, attotime_zero, 0, ATTOTIME_IN_HZ(1000)); |
| 2759 | 2690 | } |
| 2760 | 2691 | |
| 2761 | 2692 | static TIMER_CALLBACK(mouse_callback) |
| 2762 | 2693 | { |
| 2694 | rmnimbus_state *drvstate = machine->driver_data<rmnimbus_state>(); |
| 2763 | 2695 | UINT8 x = 0; |
| 2764 | 2696 | UINT8 y = 0; |
| 2765 | 2697 | // int pc=cpu_get_pc(machine->device(MAINCPU_TAG)); |
| r9685 | r9686 | |
| 2769 | 2701 | int xint; |
| 2770 | 2702 | int yint; |
| 2771 | 2703 | |
| 2772 | | _mouse_joy_state *state = &nimbus_mouse; |
| 2704 | _mouse_joy_state *state = &drvstate->nimbus_mouse; |
| 2773 | 2705 | |
| 2774 | 2706 | |
| 2775 | 2707 | state->reg0a4 = input_port_read(machine, MOUSE_BUTTON_TAG) | 0xC0; |
| r9685 | r9686 | |
| 2797 | 2729 | } |
| 2798 | 2730 | |
| 2799 | 2731 | if (y == state->mouse_y) |
| 2800 | | { |
| 2732 | { |
| 2801 | 2733 | state->mouse_py = MOUSE_PHASE_STATIC; |
| 2802 | 2734 | } |
| 2803 | 2735 | else if (y > state->mouse_y) |
| r9685 | r9686 | |
| 2826 | 2758 | state->mouse_pcy &= 0x03; |
| 2827 | 2759 | |
| 2828 | 2760 | // mxb = MOUSE_XYB[state->mouse_px][state->mouse_pcx]; // XB |
| 2829 | | // mxa = MOUSE_XYA[state->mouse_px][state->mouse_pcx]; // XA |
| 2761 | // mxa = MOUSE_XYA[state->mouse_px][state->mouse_pcx]; // XA |
| 2830 | 2762 | // mya = MOUSE_XYA[state->mouse_py][state->mouse_pcy]; // YA |
| 2831 | 2763 | // myb = MOUSE_XYB[state->mouse_py][state->mouse_pcy]; // YB |
| 2832 | 2764 | |
| r9685 | r9686 | |
| 2837 | 2769 | |
| 2838 | 2770 | if ((state->mouse_py!=MOUSE_PHASE_STATIC) || (state->mouse_px!=MOUSE_PHASE_STATIC)) |
| 2839 | 2771 | { |
| 2840 | | // logerror("state->mouse_px=%02X, state->mouse_py=%02X, state->mouse_pcx=%02X, state->mouse_pcy=%02X\n", |
| 2772 | // logerror("mouse_px=%02X, mouse_py=%02X, mouse_pcx=%02X, mouse_pcy=%02X\n", |
| 2841 | 2773 | // state->mouse_px,state->mouse_py,state->mouse_pcx,state->mouse_pcy); |
| 2842 | 2774 | |
| 2843 | 2775 | // logerror("mxb=%02x, mxa=%02X (mxb ^ mxa)=%02X, (ay8910_a & 0xC0)=%02X, (mxb ^ mxa) ^ ((ay8910_a & 0x80) >> 7)=%02X\n", |
| 2844 | | // mxb,mxa, (mxb ^ mxa) , (ay8910_a & 0xC0), (mxb ^ mxa) ^ ((ay8910_a & 0x40) >> 6)); |
| 2776 | // mxb,mxa, (mxb ^ mxa) , (state->ay8910_a & 0xC0), (mxb ^ mxa) ^ ((state->ay8910_a & 0x40) >> 6)); |
| 2845 | 2777 | } |
| 2846 | 2778 | |
| 2847 | | intstate_x = (mxb ^ mxa) ^ ((ay8910_a & 0x40) >> 6); |
| 2848 | | intstate_y = (myb ^ mya) ^ ((ay8910_a & 0x80) >> 7); |
| 2779 | intstate_x = (mxb ^ mxa) ^ ((drvstate->ay8910_a & 0x40) >> 6); |
| 2780 | intstate_y = (myb ^ mya) ^ ((drvstate->ay8910_a & 0x80) >> 7); |
| 2849 | 2781 | |
| 2850 | | if (MOUSE_INT_ENABLED()) |
| 2782 | if (MOUSE_INT_ENABLED(drvstate)) |
| 2851 | 2783 | { |
| 2852 | 2784 | if ((intstate_x==1) && (state->intstate_x==0)) |
| 2853 | 2785 | // if (intstate_x!=state->intstate_x) |
| r9685 | r9686 | |
| 2884 | 2816 | if ((state->mouse_py!=MOUSE_PHASE_STATIC) || (state->mouse_px!=MOUSE_PHASE_STATIC)) |
| 2885 | 2817 | { |
| 2886 | 2818 | // logerror("pc=%05X, reg0a4=%02X, reg092=%02X, ay_a=%02X, x=%02X, y=%02X, px=%02X, py=%02X, intstate_x=%02X, intstate_y=%02X\n", |
| 2887 | | // pc,state->reg0a4,iou_reg092,ay8910_a,state->mouse_x,state->mouse_y,state->mouse_px,state->mouse_py,intstate_x,intstate_y); |
| 2819 | // pc,state->reg0a4,state->iou_reg092,state->ay8910_a,state->mouse_x,state->mouse_y,state->mouse_px,state->mouse_py,intstate_x,intstate_y); |
| 2888 | 2820 | } |
| 2889 | 2821 | |
| 2890 | 2822 | state->intstate_x=intstate_x; |
| r9685 | r9686 | |
| 2893 | 2825 | |
| 2894 | 2826 | READ8_HANDLER( nimbus_mouse_js_r ) |
| 2895 | 2827 | { |
| 2828 | rmnimbus_state *drvstate = space->machine->driver_data<rmnimbus_state>(); |
| 2896 | 2829 | /* |
| 2897 | 2830 | |
| 2898 | 2831 | bit description |
| r9685 | r9686 | |
| 2907 | 2840 | 7 ?? always reads 1 |
| 2908 | 2841 | |
| 2909 | 2842 | */ |
| 2910 | | UINT8 result; |
| 2911 | | // int pc=cpu_get_pc(space->machine->device(MAINCPU_TAG)); |
| 2843 | UINT8 result; |
| 2844 | //int pc=cpu_get_pc(space->machine->device(MAINCPU_TAG)); |
| 2912 | 2845 | |
| 2913 | | _mouse_joy_state *state = &nimbus_mouse; |
| 2846 | _mouse_joy_state *state = &drvstate->nimbus_mouse; |
| 2914 | 2847 | |
| 2915 | 2848 | if (input_port_read(space->machine, "config") & 0x01) |
| 2916 | 2849 | { |
src/mess/video/rmnimbus.c
| r9685 | r9686 | |
| 31 | 31 | #include "debug/debugcpu.h" |
| 32 | 32 | #include "debug/debugcon.h" |
| 33 | 33 | |
| 34 | | static UINT8 video_mem[SCREEN_WIDTH_PIXELS][SCREEN_HEIGHT_LINES]; |
| 35 | 34 | |
| 36 | 35 | #define WIDTH_MASK 0x07 |
| 37 | 36 | #define XOR_MASK 0x08 |
| r9685 | r9686 | |
| 39 | 38 | |
| 40 | 39 | // Offsets of nimbus video registers within register array |
| 41 | 40 | |
| 42 | | #define NO_VIDREGS (0x30/2) |
| 43 | 41 | #define reg000 0x00 |
| 44 | 42 | #define reg002 0x01 |
| 45 | 43 | #define reg004 0x02 |
| r9685 | r9686 | |
| 65 | 63 | #define reg02C 0x16 |
| 66 | 64 | #define reg02E 0x17 |
| 67 | 65 | |
| 68 | | #define FG_COLOUR (vidregs[reg024]&0x0F) |
| 69 | | #define BG_COLOUR ((vidregs[reg024]&0xF0)>>4) |
| 66 | #define FG_COLOUR (state->vidregs[reg024]&0x0F) |
| 67 | #define BG_COLOUR ((state->vidregs[reg024]&0xF0)>>4) |
| 70 | 68 | |
| 71 | | #define IS_80COL (vidregs[reg026]&MASK_4080) |
| 72 | | #define IS_XOR (vidregs[reg022]&XOR_MASK) |
| 69 | #define IS_80COL (state->vidregs[reg026]&MASK_4080) |
| 70 | #define IS_XOR (state->vidregs[reg022]&XOR_MASK) |
| 73 | 71 | |
| 74 | 72 | |
| 75 | | static UINT16 vidregs[NO_VIDREGS]; |
| 76 | 73 | |
| 77 | | static UINT8 bpp; // Bits / pixel |
| 78 | | static UINT16 pixel_mask; |
| 79 | | static UINT8 hs_count; |
| 80 | 74 | |
| 81 | 75 | #define DEBUG_TEXT 0x01 |
| 82 | 76 | #define DEBUG_DB 0x02 |
| 83 | 77 | #define DEBUG_PIXEL 0x04 |
| 84 | 78 | |
| 85 | | #define DEBUG_SET(flags) ((debug_video & (flags))==(flags)) |
| 86 | | static UINT32 debug_video; |
| 79 | #define DEBUG_SET(flags) ((state->debug_video & (flags))==(flags)) |
| 87 | 80 | |
| 88 | | static UINT8 get_pixel(UINT16 x, UINT16 y); |
| 89 | | static UINT16 read_pixel_line(UINT16 x, UINT16 y, UINT8 width); |
| 90 | | static UINT16 read_pixel_data(UINT16 x, UINT16 y); |
| 91 | | static UINT16 read_reg_00A(void); |
| 81 | static UINT8 get_pixel(rmnimbus_state *state, UINT16 x, UINT16 y); |
| 82 | static UINT16 read_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT8 width); |
| 83 | static UINT16 read_pixel_data(rmnimbus_state *state, UINT16 x, UINT16 y); |
| 84 | static UINT16 read_reg_00A(rmnimbus_state *state); |
| 92 | 85 | |
| 93 | | static void set_pixel(UINT16 x, UINT16 y, UINT8 colour); |
| 94 | | static void write_pixel_line(UINT16 x, UINT16 y, UINT16 data, UINT8 width); |
| 95 | | static void write_pixel_data(UINT16 x, UINT16 y, UINT16 data); |
| 96 | | static void move_pixel_line(UINT16 x, UINT16 y, UINT16 data, UINT8 width); |
| 97 | | static void write_reg_004(void); |
| 98 | | static void write_reg_006(void); |
| 99 | | static void write_reg_010(void); |
| 100 | | static void write_reg_012(void); |
| 101 | | static void write_reg_014(void); |
| 102 | | static void write_reg_01A(void); |
| 103 | | static void write_reg_01C(void); |
| 104 | | static void write_reg_026(void); |
| 86 | static void set_pixel(rmnimbus_state *state, UINT16 x, UINT16 y, UINT8 colour); |
| 87 | static void write_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data, UINT8 width); |
| 88 | static void write_pixel_data(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data); |
| 89 | static void move_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data, UINT8 width); |
| 90 | static void write_reg_004(rmnimbus_state *state); |
| 91 | static void write_reg_006(rmnimbus_state *state); |
| 92 | static void write_reg_010(rmnimbus_state *state); |
| 93 | static void write_reg_012(rmnimbus_state *state); |
| 94 | static void write_reg_014(rmnimbus_state *state); |
| 95 | static void write_reg_01A(rmnimbus_state *state); |
| 96 | static void write_reg_01C(rmnimbus_state *state); |
| 97 | static void write_reg_026(rmnimbus_state *state); |
| 105 | 98 | static void change_palette(running_machine *machine, UINT8 bank, UINT16 colours, UINT8 regno); |
| 106 | 99 | |
| 107 | 100 | static void video_debug(running_machine *machine, int ref, int params, const char *param[]); |
| r9685 | r9686 | |
| 114 | 107 | |
| 115 | 108 | READ16_HANDLER (nimbus_video_io_r) |
| 116 | 109 | { |
| 110 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 117 | 111 | int pc=cpu_get_pc(space->cpu); |
| 118 | 112 | UINT16 result; |
| 119 | 113 | |
| 120 | 114 | switch (offset) |
| 121 | 115 | { |
| 122 | | case reg000 : result=vidregs[reg000]; break; |
| 123 | | case reg002 : result=vidregs[reg002]; break; |
| 124 | | case reg004 : result=vidregs[reg004]; break; |
| 125 | | case reg006 : result=vidregs[reg006]; break; |
| 126 | | case reg008 : result=vidregs[reg008]; break; |
| 127 | | case reg00A : result=read_reg_00A(); break; |
| 128 | | case reg00C : result=vidregs[reg00C]; break; |
| 129 | | case reg00E : result=vidregs[reg00E]; break; |
| 116 | case reg000 : result=state->vidregs[reg000]; break; |
| 117 | case reg002 : result=state->vidregs[reg002]; break; |
| 118 | case reg004 : result=state->vidregs[reg004]; break; |
| 119 | case reg006 : result=state->vidregs[reg006]; break; |
| 120 | case reg008 : result=state->vidregs[reg008]; break; |
| 121 | case reg00A : result=read_reg_00A(state); break; |
| 122 | case reg00C : result=state->vidregs[reg00C]; break; |
| 123 | case reg00E : result=state->vidregs[reg00E]; break; |
| 130 | 124 | |
| 131 | | case reg010 : result=vidregs[reg010]; break; |
| 132 | | case reg012 : result=vidregs[reg012]; break; |
| 133 | | case reg014 : result=vidregs[reg014]; break; |
| 134 | | case reg016 : result=vidregs[reg016]; break; |
| 135 | | case reg018 : result=vidregs[reg018]; break; |
| 136 | | case reg01A : result=vidregs[reg01A]; break; |
| 137 | | case reg01C : result=vidregs[reg01C]; break; |
| 138 | | case reg01E : result=vidregs[reg01E]; break; |
| 125 | case reg010 : result=state->vidregs[reg010]; break; |
| 126 | case reg012 : result=state->vidregs[reg012]; break; |
| 127 | case reg014 : result=state->vidregs[reg014]; break; |
| 128 | case reg016 : result=state->vidregs[reg016]; break; |
| 129 | case reg018 : result=state->vidregs[reg018]; break; |
| 130 | case reg01A : result=state->vidregs[reg01A]; break; |
| 131 | case reg01C : result=state->vidregs[reg01C]; break; |
| 132 | case reg01E : result=state->vidregs[reg01E]; break; |
| 139 | 133 | |
| 140 | | case reg020 : result=vidregs[reg020]; break; |
| 141 | | case reg022 : result=vidregs[reg022]; break; |
| 142 | | case reg024 : result=vidregs[reg024]; break; |
| 143 | | case reg026 : result=vidregs[reg026]; break; |
| 144 | | case reg028 : result=hs_count; break; //result=vidregs[reg028]; break; |
| 145 | | case reg02A : result=vidregs[reg02A]; break; |
| 146 | | case reg02C : result=vidregs[reg02C]; break; |
| 147 | | case reg02E : result=vidregs[reg02E]; break; |
| 134 | case reg020 : result=state->vidregs[reg020]; break; |
| 135 | case reg022 : result=state->vidregs[reg022]; break; |
| 136 | case reg024 : result=state->vidregs[reg024]; break; |
| 137 | case reg026 : result=state->vidregs[reg026]; break; |
| 138 | case reg028 : result=state->hs_count; break; //result=state->vidregs[reg028]; break; |
| 139 | case reg02A : result=state->vidregs[reg02A]; break; |
| 140 | case reg02C : result=state->vidregs[reg02C]; break; |
| 141 | case reg02E : result=state->vidregs[reg02E]; break; |
| 148 | 142 | default : result=0; break; |
| 149 | 143 | } |
| 150 | 144 | |
| r9685 | r9686 | |
| 154 | 148 | return result; |
| 155 | 149 | } |
| 156 | 150 | |
| 157 | | static UINT8 get_pixel(UINT16 x, UINT16 y) |
| 151 | static UINT8 get_pixel(rmnimbus_state *state, UINT16 x, UINT16 y) |
| 158 | 152 | { |
| 159 | 153 | UINT8 result = 0; |
| 160 | 154 | |
| 161 | 155 | if((x<SCREEN_WIDTH_PIXELS) && (y<SCREEN_HEIGHT_LINES)) |
| 162 | 156 | { |
| 163 | 157 | if(IS_80COL) |
| 164 | | result=video_mem[x][y]; |
| 158 | result=state->video_mem[x][y]; |
| 165 | 159 | else |
| 166 | | result=video_mem[x*2][y]; |
| 160 | result=state->video_mem[x*2][y]; |
| 167 | 161 | } |
| 168 | 162 | |
| 169 | 163 | return result; |
| 170 | 164 | } |
| 171 | 165 | |
| 172 | | static UINT16 read_pixel_line(UINT16 x, UINT16 y, UINT8 width) |
| 166 | static UINT16 read_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT8 width) |
| 173 | 167 | { |
| 174 | 168 | UINT16 result = 0; |
| 175 | 169 | UINT16 mask; |
| r9685 | r9686 | |
| 178 | 172 | UINT8 shifts; |
| 179 | 173 | |
| 180 | 174 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 181 | | logerror("read_pixel_line(x=%04X, y=%04X, width=%02X, bpp=%02X, pixel_mask=%02X)\n",x,y,width,bpp,pixel_mask); |
| 175 | logerror("read_pixel_line(x=%04X, y=%04X, width=%02X, bpp=%02X, pixel_mask=%02X)\n",x,y,width,state->bpp,state->pixel_mask); |
| 182 | 176 | |
| 183 | | shifts=width-bpp; |
| 177 | shifts=width-state->bpp; |
| 184 | 178 | |
| 185 | | for(mask=pixel_mask, pixel_x=(x*(width/bpp)); mask>0; mask=(mask>>bpp), pixel_x++) |
| 179 | for(mask=state->pixel_mask, pixel_x=(x*(width/state->bpp)); mask>0; mask=(mask>>state->bpp), pixel_x++) |
| 186 | 180 | { |
| 187 | | colour=get_pixel(pixel_x,y); |
| 181 | colour=get_pixel(state,pixel_x,y); |
| 188 | 182 | |
| 189 | | if(bpp==1) |
| 183 | if(state->bpp==1) |
| 190 | 184 | colour=((colour==FG_COLOUR) ? 1 : 0) << shifts; |
| 191 | 185 | else |
| 192 | 186 | colour=colour << shifts; |
| 193 | 187 | |
| 194 | 188 | result=(result & ~mask) | colour; |
| 195 | 189 | |
| 196 | | shifts-=bpp; |
| 190 | shifts-=state->bpp; |
| 197 | 191 | } |
| 198 | 192 | |
| 199 | 193 | return result; |
| 200 | 194 | } |
| 201 | 195 | |
| 202 | | static UINT16 read_pixel_data(UINT16 x, UINT16 y) |
| 196 | static UINT16 read_pixel_data(rmnimbus_state *state, UINT16 x, UINT16 y) |
| 203 | 197 | { |
| 204 | 198 | UINT16 result=0; |
| 205 | 199 | |
| 206 | 200 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 207 | | logerror("read_pixel_data(x=%04X, y=%04X), reg022=%04X\n",x,y,vidregs[reg022]); |
| 201 | logerror("read_pixel_data(x=%04X, y=%04X), reg022=%04X\n",x,y,state->vidregs[reg022]); |
| 208 | 202 | |
| 209 | 203 | if(IS_80COL) |
| 210 | 204 | { |
| 211 | | switch (vidregs[reg022] & WIDTH_MASK) |
| 205 | switch (state->vidregs[reg022] & WIDTH_MASK) |
| 212 | 206 | { |
| 213 | 207 | case 0x00 : break; |
| 214 | 208 | |
| r9685 | r9686 | |
| 222 | 216 | |
| 223 | 217 | case 0x05 : break; |
| 224 | 218 | |
| 225 | | case 0x06 : bpp=2; pixel_mask=0xC000; |
| 226 | | result=read_pixel_line(x,y,16); |
| 219 | case 0x06 : state->bpp=2; state->pixel_mask=0xC000; |
| 220 | result=read_pixel_line(state,x,y,16); |
| 227 | 221 | break; |
| 228 | 222 | |
| 229 | 223 | case 0x07 : break; |
| r9685 | r9686 | |
| 231 | 225 | } |
| 232 | 226 | else /* 40 Col */ |
| 233 | 227 | { |
| 234 | | switch (vidregs[reg022] & WIDTH_MASK) |
| 228 | switch (state->vidregs[reg022] & WIDTH_MASK) |
| 235 | 229 | { |
| 236 | 230 | case 0x00 : break; |
| 237 | 231 | |
| r9685 | r9686 | |
| 245 | 239 | |
| 246 | 240 | case 0x05 : break; |
| 247 | 241 | |
| 248 | | case 0x06 : bpp=4; pixel_mask=0xF000; |
| 249 | | result=read_pixel_line(x,y,16); |
| 242 | case 0x06 : state->bpp=4; state->pixel_mask=0xF000; |
| 243 | result=read_pixel_line(state,x,y,16); |
| 250 | 244 | break; |
| 251 | 245 | |
| 252 | 246 | case 0x07 : break; |
| r9685 | r9686 | |
| 256 | 250 | return result; |
| 257 | 251 | } |
| 258 | 252 | |
| 259 | | static UINT16 read_reg_00A(void) |
| 253 | static UINT16 read_reg_00A(rmnimbus_state *state) |
| 260 | 254 | { |
| 261 | | return read_pixel_data(++vidregs[reg002],vidregs[reg00C]); |
| 255 | return read_pixel_data(state, ++state->vidregs[reg002],state->vidregs[reg00C]); |
| 262 | 256 | } |
| 263 | 257 | |
| 264 | 258 | |
| r9685 | r9686 | |
| 274 | 268 | |
| 275 | 269 | WRITE16_HANDLER (nimbus_video_io_w) |
| 276 | 270 | { |
| 271 | rmnimbus_state *state = space->machine->driver_data<rmnimbus_state>(); |
| 277 | 272 | int pc=cpu_get_pc(space->cpu); |
| 278 | 273 | |
| 279 | 274 | if(offset<reg028) |
| r9685 | r9686 | |
| 287 | 282 | |
| 288 | 283 | switch (offset) |
| 289 | 284 | { |
| 290 | | case reg000 : vidregs[reg000]=data; break; |
| 291 | | case reg002 : vidregs[reg002]=data; break; |
| 292 | | case reg004 : vidregs[reg004]=data; write_reg_004(); break; |
| 293 | | case reg006 : vidregs[reg006]=data; write_reg_006(); break; |
| 294 | | case reg008 : vidregs[reg008]=data; break; |
| 295 | | case reg00A : vidregs[reg00A]=data; break; |
| 296 | | case reg00C : vidregs[reg00C]=data; break; |
| 297 | | case reg00E : vidregs[reg00E]=data; break; |
| 285 | case reg000 : state->vidregs[reg000]=data; break; |
| 286 | case reg002 : state->vidregs[reg002]=data; break; |
| 287 | case reg004 : state->vidregs[reg004]=data; write_reg_004(state); break; |
| 288 | case reg006 : state->vidregs[reg006]=data; write_reg_006(state); break; |
| 289 | case reg008 : state->vidregs[reg008]=data; break; |
| 290 | case reg00A : state->vidregs[reg00A]=data; break; |
| 291 | case reg00C : state->vidregs[reg00C]=data; break; |
| 292 | case reg00E : state->vidregs[reg00E]=data; break; |
| 298 | 293 | |
| 299 | | case reg010 : vidregs[reg010]=data; write_reg_010(); break; |
| 300 | | case reg012 : vidregs[reg012]=data; write_reg_012(); break; |
| 301 | | case reg014 : vidregs[reg014]=data; write_reg_014(); break; |
| 302 | | case reg016 : vidregs[reg016]=data; break; |
| 303 | | case reg018 : vidregs[reg018]=data; break; |
| 304 | | case reg01A : vidregs[reg01A]=data; write_reg_01A(); break; |
| 305 | | case reg01C : vidregs[reg01C]=data; write_reg_01C();break; |
| 306 | | case reg01E : vidregs[reg01E]=data; break; |
| 294 | case reg010 : state->vidregs[reg010]=data; write_reg_010(state); break; |
| 295 | case reg012 : state->vidregs[reg012]=data; write_reg_012(state); break; |
| 296 | case reg014 : state->vidregs[reg014]=data; write_reg_014(state); break; |
| 297 | case reg016 : state->vidregs[reg016]=data; break; |
| 298 | case reg018 : state->vidregs[reg018]=data; break; |
| 299 | case reg01A : state->vidregs[reg01A]=data; write_reg_01A(state); break; |
| 300 | case reg01C : state->vidregs[reg01C]=data; write_reg_01C(state);break; |
| 301 | case reg01E : state->vidregs[reg01E]=data; break; |
| 307 | 302 | |
| 308 | | case reg020 : vidregs[reg020]=data; break; |
| 309 | | case reg022 : vidregs[reg022]=data; break; |
| 310 | | case reg024 : vidregs[reg024]=data; break; |
| 311 | | case reg026 : vidregs[reg026]=data; write_reg_026(); break; |
| 303 | case reg020 : state->vidregs[reg020]=data; break; |
| 304 | case reg022 : state->vidregs[reg022]=data; break; |
| 305 | case reg024 : state->vidregs[reg024]=data; break; |
| 306 | case reg026 : state->vidregs[reg026]=data; write_reg_026(state); break; |
| 312 | 307 | case reg028 : change_palette(space->machine,0,data,reg028); break; |
| 313 | 308 | case reg02A : change_palette(space->machine,1,data,reg02A); break; |
| 314 | 309 | case reg02C : change_palette(space->machine,2,data,reg02C); break; |
| r9685 | r9686 | |
| 318 | 313 | } |
| 319 | 314 | } |
| 320 | 315 | |
| 321 | | static void set_pixel(UINT16 x, UINT16 y, UINT8 colour) |
| 316 | static void set_pixel(rmnimbus_state *state, UINT16 x, UINT16 y, UINT8 colour) |
| 322 | 317 | { |
| 323 | 318 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 324 | 319 | logerror("set_pixel(x=%04X, y=%04X, colour=%04X), IS_XOR=%02X\n",x,y,colour,IS_XOR); |
| r9685 | r9686 | |
| 329 | 324 | if((x<SCREEN_WIDTH_PIXELS) && (y<SCREEN_HEIGHT_LINES)) |
| 330 | 325 | { |
| 331 | 326 | if(IS_XOR) |
| 332 | | video_mem[x][y]^=colour; |
| 327 | state->video_mem[x][y]^=colour; |
| 333 | 328 | else |
| 334 | | video_mem[x][y]=colour; |
| 329 | state->video_mem[x][y]=colour; |
| 335 | 330 | } |
| 336 | 331 | } |
| 337 | 332 | |
| 338 | | static void set_pixel40(UINT16 x, UINT16 y, UINT8 colour) |
| 333 | static void set_pixel40(rmnimbus_state *state, UINT16 x, UINT16 y, UINT8 colour) |
| 339 | 334 | { |
| 340 | | set_pixel((x*2),y,colour); |
| 341 | | set_pixel((x*2)+1,y,colour); |
| 335 | set_pixel(state, (x*2),y,colour); |
| 336 | set_pixel(state, (x*2)+1,y,colour); |
| 342 | 337 | } |
| 343 | 338 | |
| 344 | | static void write_pixel_line(UINT16 x, UINT16 y, UINT16 data, UINT8 width) |
| 339 | static void write_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data, UINT8 width) |
| 345 | 340 | { |
| 346 | 341 | UINT16 mask; |
| 347 | 342 | UINT16 pixel_x; |
| r9685 | r9686 | |
| 349 | 344 | UINT8 shifts; |
| 350 | 345 | |
| 351 | 346 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 352 | | logerror("write_pixel_line(x=%04X, y=%04X, data=%04X, width=%02X, bpp=%02X, pixel_mask=%02X)\n",x,y,data,width,bpp,pixel_mask); |
| 347 | logerror("write_pixel_line(x=%04X, y=%04X, data=%04X, width=%02X, bpp=%02X, pixel_mask=%02X)\n",x,y,data,width,state->bpp,state->pixel_mask); |
| 353 | 348 | |
| 354 | | shifts=width-bpp; |
| 349 | shifts=width-state->bpp; |
| 355 | 350 | |
| 356 | | for(mask=pixel_mask, pixel_x=(x*(width/bpp)); mask>0; mask=(mask>>bpp), pixel_x++) |
| 351 | for(mask=state->pixel_mask, pixel_x=(x*(width/state->bpp)); mask>0; mask=(mask>>state->bpp), pixel_x++) |
| 357 | 352 | { |
| 358 | | if(bpp==1) |
| 353 | if(state->bpp==1) |
| 359 | 354 | colour=(data & mask) ? FG_COLOUR : BG_COLOUR; |
| 360 | 355 | else |
| 361 | 356 | colour=(data & mask) >> shifts; |
| 362 | 357 | |
| 363 | | //logerror("write_pixel_line: data=%04X, mask=%04X, shifts=%02X, bpp=%02X colour=%02X\n",data,mask,shifts,bpp,colour); |
| 358 | //logerror("write_pixel_line: data=%04X, mask=%04X, shifts=%02X, bpp=%02X colour=%02X\n",data,mask,shifts,state->bpp,colour); |
| 364 | 359 | |
| 365 | 360 | if(IS_80COL) |
| 366 | | set_pixel(pixel_x,y,colour); |
| 361 | set_pixel(state,pixel_x,y,colour); |
| 367 | 362 | else |
| 368 | | set_pixel40(pixel_x,y,colour); |
| 363 | set_pixel40(state,pixel_x,y,colour); |
| 369 | 364 | |
| 370 | | shifts-=bpp; |
| 365 | shifts-=state->bpp; |
| 371 | 366 | } |
| 372 | 367 | } |
| 373 | 368 | |
| 374 | | static void move_pixel_line(UINT16 x, UINT16 y, UINT16 data, UINT8 width) |
| 369 | static void move_pixel_line(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data, UINT8 width) |
| 375 | 370 | { |
| 376 | 371 | UINT16 pixelno; |
| 377 | 372 | UINT16 pixelx; |
| r9685 | r9686 | |
| 384 | 379 | pixelx=(x*width)+pixelno; |
| 385 | 380 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 386 | 381 | logerror("pixelx=%04X\n",pixelx); |
| 387 | | video_mem[pixelx][vidregs[reg020]]=video_mem[pixelx][y]; |
| 382 | state->video_mem[pixelx][state->vidregs[reg020]]=state->video_mem[pixelx][y]; |
| 388 | 383 | } |
| 389 | 384 | } |
| 390 | 385 | |
| r9685 | r9686 | |
| 415 | 410 | 1 pixels are xor'ed onto the screen |
| 416 | 411 | */ |
| 417 | 412 | |
| 418 | | static void write_pixel_data(UINT16 x, UINT16 y, UINT16 data) |
| 413 | static void write_pixel_data(rmnimbus_state *state, UINT16 x, UINT16 y, UINT16 data) |
| 419 | 414 | { |
| 420 | 415 | if(DEBUG_SET(DEBUG_TEXT | DEBUG_PIXEL)) |
| 421 | | logerror("write_pixel_data(x=%04X, y=%04X, data=%04X), reg022=%04X\n",x,y,data,vidregs[reg022]); |
| 416 | logerror("write_pixel_data(x=%04X, y=%04X, data=%04X), reg022=%04X\n",x,y,data,state->vidregs[reg022]); |
| 422 | 417 | |
| 423 | 418 | if(IS_80COL) |
| 424 | 419 | { |
| 425 | | switch (vidregs[reg022] & WIDTH_MASK) |
| 420 | switch (state->vidregs[reg022] & WIDTH_MASK) |
| 426 | 421 | { |
| 427 | | case 0x00 : bpp=1; pixel_mask=0x8000; |
| 428 | | write_pixel_line(x,y,data,16); |
| 422 | case 0x00 : state->bpp=1; state->pixel_mask=0x8000; |
| 423 | write_pixel_line(state,x,y,data,16); |
| 429 | 424 | break; |
| 430 | 425 | |
| 431 | | case 0x01 : bpp=1; pixel_mask=0x80; |
| 432 | | write_pixel_line(x,y,data,8); |
| 426 | case 0x01 : state->bpp=1; state->pixel_mask=0x80; |
| 427 | write_pixel_line(state,x,y,data,8); |
| 433 | 428 | break; |
| 434 | 429 | |
| 435 | | case 0x02 : bpp=1; pixel_mask=0x0080; |
| 436 | | write_pixel_line(x,y,data,8); |
| 430 | case 0x02 : state->bpp=1; state->pixel_mask=0x0080; |
| 431 | write_pixel_line(state,x,y,data,8); |
| 437 | 432 | break; |
| 438 | 433 | |
| 439 | | case 0x03 : bpp=1; |
| 440 | | set_pixel(x,y,FG_COLOUR); |
| 434 | case 0x03 : state->bpp=1; |
| 435 | set_pixel(state,x,y,FG_COLOUR); |
| 441 | 436 | break; |
| 442 | 437 | |
| 443 | | case 0x04 : bpp=2; pixel_mask=0xC0; |
| 444 | | write_pixel_line(x,y,((data & 0xFF) & ((data & 0xFF00)>>8)),8); |
| 438 | case 0x04 : state->bpp=2; state->pixel_mask=0xC0; |
| 439 | write_pixel_line(state,x,y,((data & 0xFF) & ((data & 0xFF00)>>8)),8); |
| 445 | 440 | break; |
| 446 | 441 | |
| 447 | | case 0x05 : move_pixel_line(x,y,data,16); |
| 442 | case 0x05 : move_pixel_line(state,x,y,data,16); |
| 448 | 443 | break; |
| 449 | 444 | |
| 450 | | case 0x06 : bpp=2; pixel_mask=0xC000; |
| 451 | | write_pixel_line(x,y,data,16); |
| 445 | case 0x06 : state->bpp=2; state->pixel_mask=0xC000; |
| 446 | write_pixel_line(state,x,y,data,16); |
| 452 | 447 | break; |
| 453 | 448 | |
| 454 | | case 0x07 : bpp=1; |
| 455 | | set_pixel(x,y,FG_COLOUR); |
| 449 | case 0x07 : state->bpp=1; |
| 450 | set_pixel(state,x,y,FG_COLOUR); |
| 456 | 451 | break; |
| 457 | 452 | } |
| 458 | 453 | } |
| 459 | 454 | else /* 40 Col */ |
| 460 | 455 | { |
| 461 | | switch (vidregs[reg022] & WIDTH_MASK) |
| 456 | switch (state->vidregs[reg022] & WIDTH_MASK) |
| 462 | 457 | { |
| 463 | | case 0x00 : bpp=1; pixel_mask=0x0080; |
| 464 | | write_pixel_line(x,y,data,8); |
| 458 | case 0x00 : state->bpp=1; state->pixel_mask=0x0080; |
| 459 | write_pixel_line(state,x,y,data,8); |
| 465 | 460 | break; |
| 466 | 461 | |
| 467 | | case 0x01 : bpp=2; pixel_mask=0xC0; |
| 468 | | write_pixel_line(x,y,data,8); |
| 462 | case 0x01 : state->bpp=2; state->pixel_mask=0xC0; |
| 463 | write_pixel_line(state,x,y,data,8); |
| 469 | 464 | break; |
| 470 | 465 | |
| 471 | | case 0x02 : bpp=1; pixel_mask=0x0080; |
| 472 | | set_pixel40(x,y,FG_COLOUR); |
| 466 | case 0x02 : state->bpp=1; state->pixel_mask=0x0080; |
| 467 | set_pixel40(state,x,y,FG_COLOUR); |
| 473 | 468 | break; |
| 474 | 469 | |
| 475 | | case 0x03 : bpp=1; |
| 476 | | set_pixel(x,y,FG_COLOUR); |
| 470 | case 0x03 : state->bpp=1; |
| 471 | set_pixel(state,x,y,FG_COLOUR); |
| 477 | 472 | break; |
| 478 | 473 | |
| 479 | | case 0x04 : bpp=4; pixel_mask=0xF0; |
| 480 | | write_pixel_line(x,y,((data & 0xFF) & ((data & 0xFF00)>>8)),8); |
| 474 | case 0x04 : state->bpp=4; state->pixel_mask=0xF0; |
| 475 | write_pixel_line(state,x,y,((data & 0xFF) & ((data & 0xFF00)>>8)),8); |
| 481 | 476 | break; |
| 482 | 477 | |
| 483 | | case 0x05 : move_pixel_line(x,y,data,16); |
| 478 | case 0x05 : move_pixel_line(state,x,y,data,16); |
| 484 | 479 | break; |
| 485 | 480 | |
| 486 | | case 0x06 : bpp=4; pixel_mask=0xF000; |
| 487 | | write_pixel_line(x,y,data,16); |
| 481 | case 0x06 : state->bpp=4; state->pixel_mask=0xF000; |
| 482 | write_pixel_line(state,x,y,data,16); |
| 488 | 483 | break; |
| 489 | 484 | |
| 490 | | case 0x07 : bpp=1; |
| 491 | | set_pixel(x,y,FG_COLOUR); |
| 485 | case 0x07 : state->bpp=1; |
| 486 | set_pixel(state,x,y,FG_COLOUR); |
| 492 | 487 | break; |
| 493 | 488 | } |
| 494 | 489 | } |
| 495 | 490 | } |
| 496 | 491 | |
| 497 | | static void write_reg_004(void) |
| 492 | static void write_reg_004(rmnimbus_state *state) |
| 498 | 493 | { |
| 499 | | vidregs[reg002]=0; |
| 500 | | vidregs[reg00C]++; |
| 494 | state->vidregs[reg002]=0; |
| 495 | state->vidregs[reg00C]++; |
| 501 | 496 | } |
| 502 | 497 | |
| 503 | | static void write_reg_006(void) |
| 498 | static void write_reg_006(rmnimbus_state *state) |
| 504 | 499 | { |
| 505 | | vidregs[reg00C]++; |
| 506 | | vidregs[reg002]=vidregs[reg006]; |
| 500 | state->vidregs[reg00C]++; |
| 501 | state->vidregs[reg002]=state->vidregs[reg006]; |
| 507 | 502 | } |
| 508 | 503 | |
| 509 | | static void write_reg_010(void) |
| 504 | static void write_reg_010(rmnimbus_state *state) |
| 510 | 505 | { |
| 511 | | write_pixel_data(vidregs[reg002],vidregs[reg00C],vidregs[reg010]); |
| 506 | write_pixel_data(state, state->vidregs[reg002],state->vidregs[reg00C],state->vidregs[reg010]); |
| 512 | 507 | } |
| 513 | 508 | |
| 514 | | static void write_reg_012(void) |
| 509 | static void write_reg_012(rmnimbus_state *state) |
| 515 | 510 | { |
| 516 | 511 | // I dunno if this is actually what is happening as the regs seem to be write only.... |
| 517 | 512 | // doing this however does seem to make some programs (worms from the welcom disk) |
| 518 | 513 | // work correctly. |
| 519 | | vidregs[reg002]=vidregs[reg012]; |
| 514 | state->vidregs[reg002]=state->vidregs[reg012]; |
| 520 | 515 | |
| 521 | | write_pixel_data(vidregs[reg012],vidregs[reg00C],FG_COLOUR); |
| 516 | write_pixel_data(state, state->vidregs[reg012],state->vidregs[reg00C],FG_COLOUR); |
| 522 | 517 | } |
| 523 | 518 | |
| 524 | | static void write_reg_014(void) |
| 519 | static void write_reg_014(rmnimbus_state *state) |
| 525 | 520 | { |
| 526 | | write_pixel_data(vidregs[reg002],vidregs[reg00C]++,vidregs[reg014]); |
| 521 | write_pixel_data(state, state->vidregs[reg002],state->vidregs[reg00C]++,state->vidregs[reg014]); |
| 527 | 522 | } |
| 528 | 523 | |
| 529 | | static void write_reg_01A(void) |
| 524 | static void write_reg_01A(rmnimbus_state *state) |
| 530 | 525 | { |
| 531 | | write_pixel_data(++vidregs[reg002],vidregs[reg00C],vidregs[reg01A]); |
| 526 | write_pixel_data(state, ++state->vidregs[reg002],state->vidregs[reg00C],state->vidregs[reg01A]); |
| 532 | 527 | } |
| 533 | 528 | |
| 534 | | static void write_reg_01C(void) |
| 529 | static void write_reg_01C(rmnimbus_state *state) |
| 535 | 530 | { |
| 536 | 531 | // I dunno if this is actually what is happening as the regs seem to be write only.... |
| 537 | 532 | // doing this however does seem to make some programs (welcome from the welcom disk, |
| 538 | 533 | // and others using the standard RM box menus) work correctly. |
| 539 | | vidregs[reg00C]=vidregs[reg01C]; |
| 534 | state->vidregs[reg00C]=state->vidregs[reg01C]; |
| 540 | 535 | |
| 541 | | write_pixel_data(vidregs[reg002],vidregs[reg01C],FG_COLOUR); |
| 536 | write_pixel_data(state, state->vidregs[reg002],state->vidregs[reg01C],FG_COLOUR); |
| 542 | 537 | } |
| 543 | 538 | |
| 544 | 539 | /* |
| r9685 | r9686 | |
| 546 | 541 | bit 5 contains the 40/80 column (320/640 pixel) flag. |
| 547 | 542 | */ |
| 548 | 543 | |
| 549 | | static void write_reg_026(void) |
| 544 | static void write_reg_026(rmnimbus_state *state) |
| 550 | 545 | { |
| 551 | 546 | if(DEBUG_SET(DEBUG_TEXT)) |
| 552 | | logerror("reg 026 write, border_colour=%02X\n",vidregs[reg026] & 0x0F); |
| 547 | logerror("reg 026 write, border_colour=%02X\n",state->vidregs[reg026] & 0x0F); |
| 553 | 548 | } |
| 554 | 549 | |
| 555 | 550 | static void change_palette(running_machine *machine, UINT8 bank, UINT16 colours, UINT8 regno) |
| 556 | 551 | { |
| 552 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 557 | 553 | UINT8 colourno; |
| 558 | 554 | UINT16 mask; |
| 559 | 555 | UINT8 shifts; |
| r9685 | r9686 | |
| 562 | 558 | UINT8 first; |
| 563 | 559 | |
| 564 | 560 | // for the register's data has changed update it, and then update the pallette, else do nothing. |
| 565 | | if(vidregs[regno]!=colours) |
| 566 | | vidregs[regno]=colours; |
| 561 | if(state->vidregs[regno]!=colours) |
| 562 | state->vidregs[regno]=colours; |
| 567 | 563 | else |
| 568 | 564 | return; |
| 569 | 565 | |
| r9685 | r9686 | |
| 589 | 585 | |
| 590 | 586 | static void video_debug(running_machine *machine, int ref, int params, const char *param[]) |
| 591 | 587 | { |
| 588 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 592 | 589 | if(params>0) |
| 593 | 590 | { |
| 594 | | sscanf(param[0],"%d",&debug_video); |
| 591 | sscanf(param[0],"%d",&state->debug_video); |
| 595 | 592 | } |
| 596 | 593 | else |
| 597 | 594 | { |
| 598 | 595 | debug_console_printf(machine,"Error usage : nimbus_vid_debug <debuglevel>\n"); |
| 599 | | debug_console_printf(machine,"Current debuglevel=%02X\n",debug_video); |
| 596 | debug_console_printf(machine,"Current debuglevel=%02X\n",state->debug_video); |
| 600 | 597 | } |
| 601 | 598 | } |
| 602 | 599 | |
| 603 | 600 | static void video_regdump(running_machine *machine, int ref, int params, const char *param[]) |
| 604 | 601 | { |
| 602 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 605 | 603 | int regno; |
| 606 | 604 | |
| 607 | 605 | for(regno=0;regno<0x08;regno++) |
| 608 | 606 | { |
| 609 | 607 | debug_console_printf(machine,"reg%03X=%04X reg%03X=%04X reg%03X=%04X\n", |
| 610 | | regno*2,vidregs[regno], |
| 611 | | (regno+0x08)*2,vidregs[regno+0x08], |
| 612 | | (regno+0x10)*2,vidregs[regno+0x10]); |
| 608 | regno*2,state->vidregs[regno], |
| 609 | (regno+0x08)*2,state->vidregs[regno+0x08], |
| 610 | (regno+0x10)*2,state->vidregs[regno+0x10]); |
| 613 | 611 | |
| 614 | 612 | logerror("reg%03X=%04X reg%03X=%04X reg%03X=%04X\n", |
| 615 | | regno*2,vidregs[regno], |
| 616 | | (regno+0x08)*2,vidregs[regno+0x08], |
| 617 | | (regno+0x10)*2,vidregs[regno+0x10]); |
| 613 | regno*2,state->vidregs[regno], |
| 614 | (regno+0x08)*2,state->vidregs[regno+0x08], |
| 615 | (regno+0x10)*2,state->vidregs[regno+0x10]); |
| 618 | 616 | } |
| 619 | 617 | } |
| 620 | 618 | |
| 621 | 619 | VIDEO_START( nimbus ) |
| 622 | 620 | { |
| 623 | | debug_video=0; |
| 621 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 622 | state->debug_video=0; |
| 624 | 623 | |
| 625 | 624 | logerror("VIDEO_START\n"); |
| 626 | 625 | |
| r9685 | r9686 | |
| 633 | 632 | |
| 634 | 633 | VIDEO_RESET( nimbus ) |
| 635 | 634 | { |
| 635 | rmnimbus_state *state = machine->driver_data<rmnimbus_state>(); |
| 636 | 636 | // When we reset clear the video registers and video memory. |
| 637 | | memset(&vidregs,0x00,sizeof(vidregs)); |
| 638 | | memset(&video_mem,0,sizeof(video_mem)); |
| 637 | memset(&state->vidregs,0x00,sizeof(state->vidregs)); |
| 638 | memset(&state->video_mem,0,sizeof(state->video_mem)); |
| 639 | 639 | |
| 640 | | bpp=4; // bits per pixel |
| 640 | state->bpp=4; // bits per pixel |
| 641 | 641 | logerror("Video reset\n"); |
| 642 | 642 | } |
| 643 | 643 | |
| r9685 | r9686 | |
| 649 | 649 | |
| 650 | 650 | VIDEO_UPDATE( nimbus ) |
| 651 | 651 | { |
| 652 | rmnimbus_state *state = screen->machine->driver_data<rmnimbus_state>(); |
| 652 | 653 | int XCoord; |
| 653 | 654 | int YCoord = screen->vpos(); |
| 654 | 655 | |
| 655 | 656 | for(XCoord=0;XCoord<SCREEN_WIDTH_PIXELS;XCoord++) |
| 656 | 657 | { |
| 657 | | *BITMAP_ADDR16(bitmap, YCoord, XCoord)=video_mem[XCoord][YCoord]; |
| 658 | *BITMAP_ADDR16(bitmap, YCoord, XCoord)=state->video_mem[XCoord][YCoord]; |
| 658 | 659 | } |
| 659 | 660 | |
| 660 | | hs_count++; |
| 661 | | if((hs_count & 0x000F)>0x0A) |
| 662 | | hs_count&=0xFFF0; |
| 661 | state->hs_count++; |
| 662 | if((state->hs_count & 0x000F)>0x0A) |
| 663 | state->hs_count&=0xFFF0; |
| 663 | 664 | |
| 664 | 665 | return 0; |
| 665 | 666 | } |
src/mess/drivers/dectalk.c
| r9685 | r9686 | |
| 148 | 148 | #include "machine/terminal.h" |
| 149 | 149 | |
| 150 | 150 | |
| 151 | | /* Components */ |
| 152 | | |
| 153 | | static struct |
| 151 | class dectalk_state : public driver_device |
| 154 | 152 | { |
| 155 | | UINT8 data[8]; // hack to prevent gcc bitching about struct pointers. not used. |
| 156 | | UINT8 x2214_sram[256]; // NVRAM chip's temp sram space |
| 157 | | UINT8 statusLED; |
| 158 | | // input fifo, between m68k and tms32010 |
| 159 | | UINT16 infifo[32]; // technically eight 74LS224 4bit*16stage FIFO chips, arranged as a 32 stage, 16-bit wide fifo |
| 160 | | UINT8 infifo_tail_ptr; |
| 161 | | UINT8 infifo_head_ptr; |
| 162 | | // output fifo, between tms32010 and 10khz sample latch for dac |
| 163 | | UINT16 outfifo[16]; // technically three 74LS224 4bit*16stage FIFO chips, arranged as a 16 stage, 12-bit wide fifo |
| 164 | | UINT8 outfifo_tail_ptr; |
| 165 | | UINT8 outfifo_head_ptr; |
| 166 | | UINT8 infifo_semaphore; // latch for status of output fifo, d-latch 74ls74 @ E64 'lower half' |
| 167 | | UINT8 spc_error_latch; // latch for error status of speech dsp, d-latch 74ls74 @ E64 'upper half' |
| 168 | | UINT8 m68k_spcflags_latch; // latch for initializing the speech dsp, d-latch 74ls74 @ E29 'lower half', AND latch for spc irq enable, d-latch 74ls74 @ E29 'upper half'; these are stored in bits 0 and 6 respectively, the rest of the bits stored here MUST be zeroed! |
| 169 | | UINT8 m68k_tlcflags_latch; // latch for telephone interface stuff, d-latches 74ls74 @ E93 'upper half' and @ 103 'upper and lower halves' |
| 170 | | UINT8 simulate_outfifo_error; // simulate an error on the outfifo, which does something unusual to the dsp latches |
| 171 | | UINT8 tlc_tonedetect; |
| 172 | | UINT8 tlc_ringdetect; |
| 173 | | UINT8 tlc_dtmf; // dtmf holding reg |
| 174 | | UINT8 duart_inport; // low 4 bits of duart input |
| 175 | | UINT8 duart_outport; // most recent duart output |
| 176 | | } dectalk={ {0}}; |
| 153 | public: |
| 154 | dectalk_state(running_machine &machine, const driver_device_config_base &config) |
| 155 | : driver_device(machine, config) { } |
| 177 | 156 | |
| 157 | UINT8 data[8]; // hack to prevent gcc bitching about struct pointers. not used. |
| 158 | UINT8 x2214_sram[256]; // NVRAM chip's temp sram space |
| 159 | UINT8 statusLED; |
| 160 | // input fifo, between m68k and tms32010 |
| 161 | UINT16 infifo[32]; // technically eight 74LS224 4bit*16stage FIFO chips, arranged as a 32 stage, 16-bit wide fifo |
| 162 | UINT8 infifo_tail_ptr; |
| 163 | UINT8 infifo_head_ptr; |
| 164 | // output fifo, between tms32010 and 10khz sample latch for dac |
| 165 | UINT16 outfifo[16]; // technically three 74LS224 4bit*16stage FIFO chips, arranged as a 16 stage, 12-bit wide fifo |
| 166 | UINT8 outfifo_tail_ptr; |
| 167 | UINT8 outfifo_head_ptr; |
| 168 | UINT8 infifo_semaphore; // latch for status of output fifo, d-latch 74ls74 @ E64 'lower half' |
| 169 | UINT8 spc_error_latch; // latch for error status of speech dsp, d-latch 74ls74 @ E64 'upper half' |
| 170 | UINT8 m68k_spcflags_latch; // latch for initializing the speech dsp, d-latch 74ls74 @ E29 'lower half', AND latch for spc irq enable, d-latch 74ls74 @ E29 'upper half'; these are stored in bits 0 and 6 respectively, the rest of the bits stored here MUST be zeroed! |
| 171 | UINT8 m68k_tlcflags_latch; // latch for telephone interface stuff, d-latches 74ls74 @ E93 'upper half' and @ 103 'upper and lower halves' |
| 172 | UINT8 simulate_outfifo_error; // simulate an error on the outfifo, which does something unusual to the dsp latches |
| 173 | UINT8 tlc_tonedetect; |
| 174 | UINT8 tlc_ringdetect; |
| 175 | UINT8 tlc_dtmf; // dtmf holding reg |
| 176 | UINT8 duart_inport; // low 4 bits of duart input |
| 177 | UINT8 duart_outport; // most recent duart output |
| 178 | UINT8 hack_self_test; // temp variable for hack below |
| 179 | }; |
| 180 | |
| 181 | |
| 178 | 182 | /* Devices */ |
| 179 | 183 | static void duart_irq_handler(running_device *device, UINT8 vector) |
| 180 | 184 | { |
| 181 | | cputag_set_input_line_and_vector(device->machine, "maincpu", M68K_IRQ_6, HOLD_LINE, M68K_INT_ACK_AUTOVECTOR); |
| 182 | | //cputag_set_input_line_and_vector(device->machine, "maincpu", M68K_IRQ_6, CLEAR_LINE, M68K_INT_ACK_AUTOVECTOR); |
| 185 | cputag_set_input_line_and_vector(device->machine, "maincpu", M68K_IRQ_6, HOLD_LINE, M68K_INT_ACK_AUTOVECTOR); |
| 186 | //cputag_set_input_line_and_vector(device->machine, "maincpu", M68K_IRQ_6, CLEAR_LINE, M68K_INT_ACK_AUTOVECTOR); |
| 183 | 187 | //cputag_set_input_line_and_vector(device->machine, "maincpu", M68K_IRQ_6, HOLD_LINE, vector); |
| 184 | 188 | }; |
| 185 | 189 | |
| 186 | | static UINT8 hack_self_test = 0; // temp variable for hack below |
| 187 | | |
| 188 | 190 | static UINT8 duart_input(running_device *device) |
| 189 | 191 | { |
| 192 | dectalk_state *state = device->machine->driver_data<dectalk_state>(); |
| 190 | 193 | UINT8 data = 0; |
| 191 | | data |= dectalk.duart_inport&0xF; |
| 194 | data |= state->duart_inport&0xF; |
| 192 | 195 | data |= (input_port_read(device->machine, "duart_in")&0xF0); |
| 193 | | if ((hack_self_test == 1) && (input_port_read(device->machine, "hacks")&0x01)) data |= 0x10; // hack to prevent hang if selftest disable bit is kept low past the first read; i suppose the proper use of this bit was an incremental switch, or perhaps its expecting an interrupt later from serial in or tone in? added a dipswitch to disable the hack for testing |
| 194 | | hack_self_test = 1; |
| 196 | if ((state->hack_self_test == 1) && (input_port_read(device->machine, "hacks")&0x01)) data |= 0x10; // hack to prevent hang if selftest disable bit is kept low past the first read; i suppose the proper use of this bit was an incremental switch, or perhaps its expecting an interrupt later from serial in or tone in? added a dipswitch to disable the hack for testing |
| 197 | state->hack_self_test = 1; |
| 195 | 198 | return data; |
| 196 | 199 | } |
| 197 | 200 | |
| 198 | 201 | static void duart_output(running_device *device, UINT8 data) |
| 199 | 202 | { |
| 200 | | dectalk.duart_outport = data; |
| 203 | dectalk_state *state = device->machine->driver_data<dectalk_state>(); |
| 204 | state->duart_outport = data; |
| 201 | 205 | #ifdef SERIAL_TO_STDERR |
| 202 | 206 | fprintf(stderr, "RTS: %01X, DTR: %01X\n", data&1, (data&4)>>2); |
| 203 | 207 | #endif |
| r9685 | r9686 | |
| 220 | 224 | duart_output |
| 221 | 225 | }; |
| 222 | 226 | |
| 223 | | #define SPC_INITIALIZE dectalk.m68k_spcflags_latch&0x1 // speech initialize flag |
| 224 | | #define SPC_IRQ_ENABLED ((dectalk.m68k_spcflags_latch&0x40)>>6) // irq enable flag |
| 227 | #define SPC_INITIALIZE state->m68k_spcflags_latch&0x1 // speech initialize flag |
| 228 | #define SPC_IRQ_ENABLED ((state->m68k_spcflags_latch&0x40)>>6) // irq enable flag |
| 225 | 229 | |
| 226 | 230 | static void dectalk_outfifo_check (running_machine *machine) |
| 227 | 231 | { |
| 232 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 228 | 233 | // check if output fifo is full; if it isn't, set the int on the dsp |
| 229 | | if (((dectalk.outfifo_head_ptr-1)&0xF) != dectalk.outfifo_tail_ptr) |
| 234 | if (((state->outfifo_head_ptr-1)&0xF) != state->outfifo_tail_ptr) |
| 230 | 235 | cputag_set_input_line(machine, "dsp", 0, ASSERT_LINE); // TMS32010 INT |
| 231 | 236 | else |
| 232 | 237 | cputag_set_input_line(machine, "dsp", 0, CLEAR_LINE); // TMS32010 INT |
| r9685 | r9686 | |
| 234 | 239 | |
| 235 | 240 | static void dectalk_clear_all_fifos( running_machine *machine ) |
| 236 | 241 | { |
| 242 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 237 | 243 | // clear fifos (TODO: memset would work better here...) |
| 238 | 244 | int i; |
| 239 | | for (i=0; i<16; i++) dectalk.outfifo[i] = 0; |
| 240 | | for (i=0; i<32; i++) dectalk.infifo[i] = 0; |
| 241 | | dectalk.outfifo_tail_ptr = dectalk.outfifo_head_ptr = 0; |
| 242 | | dectalk.infifo_tail_ptr = dectalk.infifo_head_ptr = 0; |
| 245 | for (i=0; i<16; i++) state->outfifo[i] = 0; |
| 246 | for (i=0; i<32; i++) state->infifo[i] = 0; |
| 247 | state->outfifo_tail_ptr = state->outfifo_head_ptr = 0; |
| 248 | state->infifo_tail_ptr = state->infifo_head_ptr = 0; |
| 243 | 249 | dectalk_outfifo_check(machine); |
| 244 | 250 | } |
| 245 | 251 | |
| 246 | 252 | static void dectalk_x2212_store( running_machine *machine ) |
| 247 | 253 | { |
| 254 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 248 | 255 | UINT8 *nvram = memory_region(machine, "nvram"); |
| 249 | 256 | int i; |
| 250 | 257 | for (i = 0; i < 256; i++) |
| 251 | | nvram[i] = dectalk.x2214_sram[i]; |
| 258 | nvram[i] = state->x2214_sram[i]; |
| 252 | 259 | #ifdef NVRAM_LOG |
| 253 | 260 | logerror("nvram store done\n"); |
| 254 | 261 | #endif |
| r9685 | r9686 | |
| 256 | 263 | |
| 257 | 264 | static void dectalk_x2212_recall( running_machine *machine ) |
| 258 | 265 | { |
| 266 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 259 | 267 | UINT8 *nvram = memory_region(machine, "nvram"); |
| 260 | 268 | int i; |
| 261 | 269 | for (i = 0; i < 256; i++) |
| 262 | | dectalk.x2214_sram[i] = nvram[i]; |
| 270 | state->x2214_sram[i] = nvram[i]; |
| 263 | 271 | #ifdef NVRAM_LOG |
| 264 | 272 | logerror("nvram recall done\n"); |
| 265 | 273 | #endif |
| r9685 | r9686 | |
| 268 | 276 | // helper for dsp infifo_semaphore flag to make dealing with interrupts easier |
| 269 | 277 | static void dectalk_semaphore_w ( running_machine *machine, UINT16 data ) |
| 270 | 278 | { |
| 271 | | dectalk.infifo_semaphore = data&1; |
| 272 | | if ((dectalk.infifo_semaphore == 1) && (dectalk.m68k_spcflags_latch&0x40)) |
| 279 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 280 | state->infifo_semaphore = data&1; |
| 281 | if ((state->infifo_semaphore == 1) && (state->m68k_spcflags_latch&0x40)) |
| 273 | 282 | { |
| 274 | 283 | #ifdef VERBOSE |
| 275 | 284 | logerror("speech int fired!\n"); |
| r9685 | r9686 | |
| 283 | 292 | // read the output fifo and set the interrupt line active on the dsp |
| 284 | 293 | static UINT16 dectalk_outfifo_r ( running_machine *machine ) |
| 285 | 294 | { |
| 295 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 286 | 296 | UINT16 data = 0xFFFF; |
| 287 | | data = dectalk.outfifo[dectalk.outfifo_tail_ptr]; |
| 297 | data = state->outfifo[state->outfifo_tail_ptr]; |
| 288 | 298 | // if fifo is empty (tail ptr == head ptr), do not increment the tail ptr, otherwise do. |
| 289 | | //if (dectalk.outfifo_tail_ptr != dectalk.outfifo_head_ptr) dectalk.outfifo_tail_ptr++; // technically correct but doesn't match sn74ls224 sheet |
| 290 | | if (((dectalk.outfifo_head_ptr-1)&0xF) != dectalk.outfifo_tail_ptr) dectalk.outfifo_tail_ptr++; // matches sn74ls224 sheet |
| 291 | | dectalk.outfifo_tail_ptr&=0xF; |
| 299 | //if (state->outfifo_tail_ptr != state->outfifo_head_ptr) state->outfifo_tail_ptr++; // technically correct but doesn't match sn74ls224 sheet |
| 300 | if (((state->outfifo_head_ptr-1)&0xF) != state->outfifo_tail_ptr) state->outfifo_tail_ptr++; // matches sn74ls224 sheet |
| 301 | state->outfifo_tail_ptr&=0xF; |
| 292 | 302 | dectalk_outfifo_check(machine); |
| 293 | 303 | return ((data&0xfff0)^0x8000); // yes this is right, top bit is inverted and bottom 4 are ignored |
| 294 | 304 | //return data; // not right but want to get it working first |
| r9685 | r9686 | |
| 297 | 307 | /* Machine reset and friends: stuff that needs setting up which IS directly affected by reset */ |
| 298 | 308 | static void dectalk_reset(running_device *device) |
| 299 | 309 | { |
| 310 | dectalk_state *state = device->machine->driver_data<dectalk_state>(); |
| 300 | 311 | const running_device *devconf = device->machine->device("duart68681"); // this is probably an evil disgusting hack, and AaronGiles is gonna throttle me for doing this... |
| 301 | | hack_self_test = 0; // hack |
| 312 | state->hack_self_test = 0; // hack |
| 302 | 313 | // stuff that is DIRECTLY affected by the RESET line |
| 303 | | dectalk.statusLED = 0; // clear status led latch |
| 314 | state->statusLED = 0; // clear status led latch |
| 304 | 315 | dectalk_x2212_recall(device->machine); // nvram recall |
| 305 | | dectalk.m68k_spcflags_latch = 1; // initial status is speech reset(d0) active and spc int(d6) disabled |
| 306 | | dectalk.m68k_tlcflags_latch = 0; // initial status is tone detect int(d6) off, answer phone(d8) off, ring detect int(d14) off |
| 316 | state->m68k_spcflags_latch = 1; // initial status is speech reset(d0) active and spc int(d6) disabled |
| 317 | state->m68k_tlcflags_latch = 0; // initial status is tone detect int(d6) off, answer phone(d8) off, ring detect int(d14) off |
| 307 | 318 | DEVICE_RESET(devconf); // reset the DUART |
| 308 | 319 | devconf = devconf; // hack to make gcc shut up about unused variables. the variable IS USED! |
| 309 | 320 | //device->machine->device("duart68681")->reset(); // reset the DUART |
| 310 | 321 | // stuff that is INDIRECTLY affected by the RESET line |
| 311 | 322 | dectalk_clear_all_fifos(device->machine); // speech reset clears the fifos, though we have to do it explicitly here since we're not actually in the m68k_spcflags_w function. |
| 312 | | dectalk_semaphore_w(device->machine, 0); // on the original dectalk pcb revision, this is a semaphore for the INPUT fifo, later dec hacked on a check for the 3 output fifo chips to see if they're in sync, and set both of these latches if true. |
| 313 | | dectalk.spc_error_latch = 0; // spc error latch is cleared on /reset |
| 323 | dectalk_semaphore_w(device->machine, 0); // on the original state->dectalk pcb revision, this is a semaphore for the INPUT fifo, later dec hacked on a check for the 3 output fifo chips to see if they're in sync, and set both of these latches if true. |
| 324 | state->spc_error_latch = 0; // spc error latch is cleared on /reset |
| 314 | 325 | cputag_set_input_line(device->machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE); // speech reset forces the CLR line active on the tms32010 |
| 315 | | dectalk.tlc_tonedetect = 0; // TODO, needed for selftest pass |
| 316 | | dectalk.tlc_ringdetect = 0; // TODO |
| 317 | | dectalk.tlc_dtmf = 0; // TODO |
| 318 | | dectalk.duart_inport = 0xF; |
| 319 | | dectalk.duart_outport = 0; |
| 326 | state->tlc_tonedetect = 0; // TODO, needed for selftest pass |
| 327 | state->tlc_ringdetect = 0; // TODO |
| 328 | state->tlc_dtmf = 0; // TODO |
| 329 | state->duart_inport = 0xF; |
| 330 | state->duart_outport = 0; |
| 320 | 331 | } |
| 321 | 332 | |
| 322 | 333 | static MACHINE_RESET( dectalk ) |
| r9685 | r9686 | |
| 328 | 339 | /* Begin 68k i/o handlers */ |
| 329 | 340 | static READ8_HANDLER( nvram_read ) // read from x2212 nvram chip and possibly do recall |
| 330 | 341 | { |
| 342 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 331 | 343 | UINT8 data = 0xFF; |
| 332 | | data = dectalk.x2214_sram[offset&0xff]; // TODO: should this be before or after a possible /RECALL? I'm guessing before. |
| 344 | data = state->x2214_sram[offset&0xff]; // TODO: should this be before or after a possible /RECALL? I'm guessing before. |
| 333 | 345 | #ifdef NVRAM_LOG |
| 334 | 346 | logerror("m68k: nvram read at %08X: %02X\n", offset, data); |
| 335 | 347 | #endif |
| r9685 | r9686 | |
| 340 | 352 | |
| 341 | 353 | static WRITE8_HANDLER( led_write ) |
| 342 | 354 | { |
| 343 | | dectalk.statusLED = data&0xFF; |
| 355 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 356 | state->statusLED = data&0xFF; |
| 344 | 357 | popmessage("LED status: %02X\n", data&0xFF); |
| 345 | 358 | #ifdef VERBOSE |
| 346 | 359 | logerror("m68k: LED status: %02X\n", data&0xFF); |
| r9685 | r9686 | |
| 350 | 363 | |
| 351 | 364 | static WRITE8_HANDLER( nvram_write ) // write to X2212 NVRAM chip and possibly do store |
| 352 | 365 | { |
| 366 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 353 | 367 | #ifdef NVRAM_LOG |
| 354 | 368 | logerror("m68k: nvram write at %08X: %02X\n", offset, data&0x0f); |
| 355 | 369 | #endif |
| 356 | | dectalk.x2214_sram[offset&0xff] = (UINT8)data&0x0f; // TODO: should this be before or after a possible /STORE? I'm guessing before. |
| 370 | state->x2214_sram[offset&0xff] = (UINT8)data&0x0f; // TODO: should this be before or after a possible /STORE? I'm guessing before. |
| 357 | 371 | if (offset&0x200) // if a9 is set, do a /STORE |
| 358 | 372 | dectalk_x2212_store(space->machine); |
| 359 | 373 | } |
| 360 | 374 | |
| 361 | 375 | static WRITE16_HANDLER( m68k_infifo_w ) // 68k write to the speech input fifo |
| 362 | 376 | { |
| 377 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 363 | 378 | #ifdef USE_LOOSE_TIMING |
| 364 | 379 | cpuexec_boost_interleave(space->machine, attotime_zero, ATTOTIME_IN_USEC(25)); |
| 365 | 380 | #endif |
| 366 | 381 | #ifdef SPC_LOG_68K |
| 367 | | logerror("m68k: SPC infifo written with data = %04X, fifo head was: %02X; fifo tail: %02X\n",data, dectalk.infifo_head_ptr, dectalk.infifo_tail_ptr); |
| 382 | logerror("m68k: SPC infifo written with data = %04X, fifo head was: %02X; fifo tail: %02X\n",data, state->infifo_head_ptr, state->infifo_tail_ptr); |
| 368 | 383 | #endif |
| 369 | 384 | // if fifo is full (head ptr = tail ptr-1), do not increment the head ptr and do not store the data |
| 370 | | if (((dectalk.infifo_tail_ptr-1)&0x1F) == dectalk.infifo_head_ptr) |
| 385 | if (((state->infifo_tail_ptr-1)&0x1F) == state->infifo_head_ptr) |
| 371 | 386 | { |
| 372 | 387 | #ifdef SPC_LOG_68K |
| 373 | 388 | logerror("infifo was full, write ignored!\n"); |
| 374 | 389 | #endif |
| 375 | 390 | return; |
| 376 | 391 | } |
| 377 | | dectalk.infifo[dectalk.infifo_head_ptr] = data; |
| 378 | | dectalk.infifo_head_ptr++; |
| 379 | | dectalk.infifo_head_ptr&=0x1F; |
| 392 | state->infifo[state->infifo_head_ptr] = data; |
| 393 | state->infifo_head_ptr++; |
| 394 | state->infifo_head_ptr&=0x1F; |
| 380 | 395 | } |
| 381 | 396 | |
| 382 | 397 | static READ16_HANDLER( m68k_spcflags_r ) // 68k read from the speech flags |
| 383 | 398 | { |
| 399 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 384 | 400 | UINT8 data = 0; |
| 385 | | data |= dectalk.m68k_spcflags_latch; // bits 0 and 6 |
| 386 | | data |= dectalk.spc_error_latch<<5; // bit 5 |
| 387 | | data |= dectalk.infifo_semaphore<<7; // bit 7 |
| 401 | data |= state->m68k_spcflags_latch; // bits 0 and 6 |
| 402 | data |= state->spc_error_latch<<5; // bit 5 |
| 403 | data |= state->infifo_semaphore<<7; // bit 7 |
| 388 | 404 | #ifdef SPC_LOG_68K |
| 389 | 405 | logerror("m68k: SPC flags read, returning data = %04X\n",data); |
| 390 | 406 | #endif |
| r9685 | r9686 | |
| 393 | 409 | |
| 394 | 410 | static WRITE16_HANDLER( m68k_spcflags_w ) // 68k write to the speech flags (only 3 bits do anything) |
| 395 | 411 | { |
| 412 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 396 | 413 | #ifdef USE_LOOSE_TIMING |
| 397 | 414 | cpuexec_boost_interleave(space->machine, attotime_zero, ATTOTIME_IN_USEC(25)); |
| 398 | 415 | #endif |
| 399 | 416 | #ifdef SPC_LOG_68K |
| 400 | 417 | logerror("m68k: SPC flags written with %04X, only storing %04X\n",data, data&0x41); |
| 401 | 418 | #endif |
| 402 | | dectalk.m68k_spcflags_latch = data&0x41; // ONLY store bits 6 and 0! |
| 419 | state->m68k_spcflags_latch = data&0x41; // ONLY store bits 6 and 0! |
| 403 | 420 | // d0: initialize speech flag (reset tms32010 and clear infifo and outfifo if high) |
| 404 | 421 | if ((data&0x1) == 0x1) // bit 0 |
| 405 | 422 | { |
| r9685 | r9686 | |
| 409 | 426 | dectalk_clear_all_fifos(space->machine); |
| 410 | 427 | cputag_set_input_line(space->machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE); // speech reset forces the CLR line active on the tms32010 |
| 411 | 428 | // clear the two speech side latches |
| 412 | | dectalk.spc_error_latch = 0; |
| 429 | state->spc_error_latch = 0; |
| 413 | 430 | dectalk_semaphore_w(space->machine, 0); |
| 414 | 431 | } |
| 415 | 432 | else // (data&0x1) == 0 |
| r9685 | r9686 | |
| 425 | 442 | logerror(" | 0x02: clear error+semaphore latches\n"); |
| 426 | 443 | #endif |
| 427 | 444 | // clear the two speech side latches |
| 428 | | dectalk.spc_error_latch = 0; |
| 445 | state->spc_error_latch = 0; |
| 429 | 446 | dectalk_semaphore_w(space->machine, 0); |
| 430 | 447 | } |
| 431 | 448 | if ((data&0x40) == 0x40) // bit 6 - spc irq enable |
| r9685 | r9686 | |
| 433 | 450 | #ifdef SPC_LOG_68K |
| 434 | 451 | logerror(" | 0x40: speech int enabled\n"); |
| 435 | 452 | #endif |
| 436 | | if ((dectalk.infifo_semaphore == 1)) |
| 453 | if ((state->infifo_semaphore == 1)) |
| 437 | 454 | { |
| 438 | 455 | #ifdef SPC_LOG_68K |
| 439 | 456 | logerror(" speech int fired!\n"); |
| r9685 | r9686 | |
| 452 | 469 | |
| 453 | 470 | static READ16_HANDLER( m68k_tlcflags_r ) // dtmf flags read |
| 454 | 471 | { |
| 472 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 455 | 473 | UINT16 data = 0; |
| 456 | | data |= dectalk.m68k_tlcflags_latch; // bits 6, 8, 14; |
| 457 | | data |= dectalk.tlc_tonedetect<<7; // bit 7 is tone detect |
| 458 | | data |= dectalk.tlc_ringdetect<<14; // bit 15 is ring detect |
| 474 | data |= state->m68k_tlcflags_latch; // bits 6, 8, 14; |
| 475 | data |= state->tlc_tonedetect<<7; // bit 7 is tone detect |
| 476 | data |= state->tlc_ringdetect<<14; // bit 15 is ring detect |
| 459 | 477 | #ifdef TLC_LOG |
| 460 | 478 | logerror("m68k: TLC flags read, returning data = %04X\n",data); |
| 461 | 479 | #endif |
| r9685 | r9686 | |
| 464 | 482 | |
| 465 | 483 | static WRITE16_HANDLER( m68k_tlcflags_w ) // dtmf flags write |
| 466 | 484 | { |
| 485 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 467 | 486 | #ifdef TLC_LOG |
| 468 | 487 | logerror("m68k: TLC flags written with %04X, only storing %04X\n",data, data&0x4140); |
| 469 | 488 | #endif |
| 470 | | dectalk.m68k_tlcflags_latch = data&0x4140; // ONLY store bits 6 8 and 14! |
| 489 | state->m68k_tlcflags_latch = data&0x4140; // ONLY store bits 6 8 and 14! |
| 471 | 490 | if ((data&0x40) == 0x40) // bit 6: tone detect interrupt enable |
| 472 | 491 | { |
| 473 | 492 | #ifdef TLC_LOG |
| 474 | 493 | logerror(" | 0x40: tone detect int enabled\n"); |
| 475 | 494 | #endif |
| 476 | | if ((dectalk.tlc_tonedetect == 1)) |
| 495 | if ((state->tlc_tonedetect == 1)) |
| 477 | 496 | { |
| 478 | 497 | #ifdef TLC_LOG |
| 479 | 498 | logerror(" TLC int fired!\n"); |
| r9685 | r9686 | |
| 486 | 505 | #ifdef TLC_LOG |
| 487 | 506 | logerror(" | 0x40 = 0: tone detect int disabled\n"); |
| 488 | 507 | #endif |
| 489 | | if (((data&0x4000)!=0x4000) || (dectalk.tlc_ringdetect == 0)) // check to be sure we don't disable int if both ints fired at once |
| 508 | if (((data&0x4000)!=0x4000) || (state->tlc_ringdetect == 0)) // check to be sure we don't disable int if both ints fired at once |
| 490 | 509 | cputag_set_input_line_and_vector(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE, M68K_INT_ACK_AUTOVECTOR); // clear int because int is now disabled |
| 491 | 510 | } |
| 492 | 511 | if ((data&0x100) == 0x100) // bit 8: answer phone relay enable |
| r9685 | r9686 | |
| 506 | 525 | #ifdef TLC_LOG |
| 507 | 526 | logerror(" | 0x4000: ring detect int enabled\n"); |
| 508 | 527 | #endif |
| 509 | | if ((dectalk.tlc_ringdetect == 1)) |
| 528 | if ((state->tlc_ringdetect == 1)) |
| 510 | 529 | { |
| 511 | 530 | #ifdef TLC_LOG |
| 512 | 531 | logerror(" TLC int fired!\n"); |
| r9685 | r9686 | |
| 519 | 538 | #ifdef TLC_LOG |
| 520 | 539 | logerror(" | 0x4000 = 0: ring detect int disabled\n"); |
| 521 | 540 | #endif |
| 522 | | if (((data&0x40)!=0x40) || (dectalk.tlc_tonedetect == 0)) // check to be sure we don't disable int if both ints fired at once |
| 541 | if (((data&0x40)!=0x40) || (state->tlc_tonedetect == 0)) // check to be sure we don't disable int if both ints fired at once |
| 523 | 542 | cputag_set_input_line_and_vector(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE, M68K_INT_ACK_AUTOVECTOR); // clear int because int is now disabled |
| 524 | 543 | } |
| 525 | 544 | } |
| 526 | 545 | |
| 527 | 546 | static READ16_HANDLER( m68k_tlc_dtmf_r ) // dtmf chip read |
| 528 | 547 | { |
| 548 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 529 | 549 | UINT16 data = 0xFFFF; |
| 530 | | data = dectalk.tlc_dtmf&0xF; |
| 550 | data = state->tlc_dtmf&0xF; |
| 531 | 551 | #ifdef TLC_LOG |
| 532 | 552 | logerror("m68k: TLC dtmf detector read, returning data = %02X", data); |
| 533 | 553 | #endif |
| r9685 | r9686 | |
| 538 | 558 | /* Begin tms32010 i/o handlers */ |
| 539 | 559 | static WRITE16_HANDLER( spc_latch_outfifo_error_stats ) // latch 74ls74 @ E64 upper and lower halves with d0 and 1 respectively |
| 540 | 560 | { |
| 561 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 541 | 562 | #ifdef USE_LOOSE_TIMING |
| 542 | 563 | cpuexec_boost_interleave(space->machine, attotime_zero, ATTOTIME_IN_USEC(25)); |
| 543 | 564 | #endif |
| 544 | 565 | #ifdef SPC_LOG_DSP |
| 545 | 566 | logerror("dsp: set fifo semaphore and set error status = %01X\n",data&1); |
| 546 | 567 | #endif |
| 547 | | dectalk_semaphore_w(space->machine, (~dectalk.simulate_outfifo_error)&1); // always set to 1 here, unless outfifo error. |
| 548 | | dectalk.spc_error_latch = (data&1); |
| 568 | dectalk_semaphore_w(space->machine, (~state->simulate_outfifo_error)&1); // always set to 1 here, unless outfifo error. |
| 569 | state->spc_error_latch = (data&1); |
| 549 | 570 | } |
| 550 | 571 | |
| 551 | 572 | static READ16_HANDLER( spc_infifo_data_r ) |
| 552 | 573 | { |
| 574 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 553 | 575 | UINT16 data = 0xFFFF; |
| 554 | | data = dectalk.infifo[dectalk.infifo_tail_ptr]; |
| 576 | data = state->infifo[state->infifo_tail_ptr]; |
| 555 | 577 | #ifdef SPC_LOG_DSP |
| 556 | | logerror("dsp: SPC infifo read with data = %04X, fifo head: %02X; fifo tail was: %02X\n",data, dectalk.infifo_head_ptr, dectalk.infifo_tail_ptr); |
| 578 | logerror("dsp: SPC infifo read with data = %04X, fifo head: %02X; fifo tail was: %02X\n",data, state->infifo_head_ptr, state->infifo_tail_ptr); |
| 557 | 579 | #endif |
| 558 | 580 | // if fifo is empty (tail ptr == head ptr), do not increment the tail ptr, otherwise do. |
| 559 | | if (dectalk.infifo_tail_ptr != dectalk.infifo_head_ptr) dectalk.infifo_tail_ptr++; // technically correct but doesn't match sn74ls224 sheet |
| 560 | | //if (((dectalk.infifo_head_ptr-1)&0x1F) != dectalk.infifo_tail_ptr) dectalk.infifo_tail_ptr++; // matches sn74ls224 sheet |
| 561 | | dectalk.infifo_tail_ptr&=0x1F; |
| 581 | if (state->infifo_tail_ptr != state->infifo_head_ptr) state->infifo_tail_ptr++; // technically correct but doesn't match sn74ls224 sheet |
| 582 | //if (((state->infifo_head_ptr-1)&0x1F) != state->infifo_tail_ptr) state->infifo_tail_ptr++; // matches sn74ls224 sheet |
| 583 | state->infifo_tail_ptr&=0x1F; |
| 562 | 584 | return data; |
| 563 | 585 | } |
| 564 | 586 | |
| 565 | 587 | static WRITE16_HANDLER( spc_outfifo_data_w ) |
| 566 | 588 | { |
| 589 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 567 | 590 | // the low 4 data bits are thrown out on the real unit due to use of a 12 bit dac (and to save use of another 16x4 fifo chip), though technically they're probably valid, and with suitable hacking a dtc-01 could probably output full 16 bit samples at 10khz. |
| 568 | 591 | #ifdef SPC_LOG_DSP |
| 569 | | logerror("dsp: SPC outfifo write, data = %04X, fifo head was: %02X; fifo tail: %02X\n", data, dectalk.outfifo_head_ptr, dectalk.outfifo_tail_ptr); |
| 592 | logerror("dsp: SPC outfifo write, data = %04X, fifo head was: %02X; fifo tail: %02X\n", data, state->outfifo_head_ptr, state->outfifo_tail_ptr); |
| 570 | 593 | #endif |
| 571 | 594 | cputag_set_input_line(space->machine, "dsp", 0, CLEAR_LINE); //TMS32010 INT (cleared because LDCK inverts the IR line, clearing int on any outfifo write... for a moment at least.) |
| 572 | 595 | // if fifo is full (head ptr = tail ptr-1), do not increment the head ptr and do not store the data |
| 573 | | if (((dectalk.outfifo_tail_ptr-1)&0xF) == dectalk.outfifo_head_ptr) |
| 596 | if (((state->outfifo_tail_ptr-1)&0xF) == state->outfifo_head_ptr) |
| 574 | 597 | { |
| 575 | 598 | #ifdef SPC_LOG_DSP |
| 576 | 599 | logerror("outfifo was full, write ignored!\n"); |
| 577 | 600 | #endif |
| 578 | 601 | return; |
| 579 | 602 | } |
| 580 | | dectalk.outfifo[dectalk.outfifo_head_ptr] = data; |
| 581 | | dectalk.outfifo_head_ptr++; |
| 582 | | dectalk.outfifo_head_ptr&=0xF; |
| 603 | state->outfifo[state->outfifo_head_ptr] = data; |
| 604 | state->outfifo_head_ptr++; |
| 605 | state->outfifo_head_ptr&=0xF; |
| 583 | 606 | //dectalk_outfifo_check(space->machine); // commented to allow int to clear |
| 584 | 607 | } |
| 585 | 608 | |
| 586 | 609 | static READ16_HANDLER( spc_semaphore_r ) // Return state of d-latch 74ls74 @ E64 'lower half' in d0 which indicates whether infifo is readable |
| 587 | 610 | { |
| 611 | dectalk_state *state = space->machine->driver_data<dectalk_state>(); |
| 588 | 612 | #ifdef SPC_LOG_DSP |
| 589 | | //logerror("dsp: read infifo semaphore, returned %d\n", dectalk.infifo_semaphore); // commented due to extreme annoyance factor |
| 590 | | if (!dectalk.infifo_semaphore) logerror("dsp: read infifo semaphore, returned %d\n", dectalk.infifo_semaphore); |
| 613 | //logerror("dsp: read infifo semaphore, returned %d\n", state->infifo_semaphore); // commented due to extreme annoyance factor |
| 614 | if (!state->infifo_semaphore) logerror("dsp: read infifo semaphore, returned %d\n", state->infifo_semaphore); |
| 591 | 615 | #endif |
| 592 | | return dectalk.infifo_semaphore; |
| 616 | return state->infifo_semaphore; |
| 593 | 617 | } |
| 594 | 618 | /* end tms32010 i/o handlers */ |
| 595 | 619 | |
| r9685 | r9686 | |
| 687 | 711 | /* Driver init: stuff that needs setting up which isn't directly affected by reset */ |
| 688 | 712 | static DRIVER_INIT( dectalk ) |
| 689 | 713 | { |
| 714 | dectalk_state *state = machine->driver_data<dectalk_state>(); |
| 690 | 715 | dectalk_clear_all_fifos(machine); |
| 691 | | dectalk.simulate_outfifo_error = 0; |
| 716 | state->simulate_outfifo_error = 0; |
| 692 | 717 | timer_set(machine, ATTOTIME_IN_HZ(10000), NULL, 0, outfifo_read_cb); |
| 693 | 718 | } |
| 694 | 719 | |
| r9685 | r9686 | |
| 702 | 727 | DEVCB_HANDLER(dectalk_kbd_put) |
| 703 | 728 | }; |
| 704 | 729 | |
| 705 | | static MACHINE_CONFIG_START( dectalk, driver_device ) |
| 730 | static MACHINE_CONFIG_START( dectalk, dectalk_state ) |
| 706 | 731 | /* basic machine hardware */ |
| 707 | 732 | MDRV_CPU_ADD("maincpu", M68000, XTAL_20MHz/2) /* E74 20MHz OSC (/2) */ |
| 708 | 733 | MDRV_CPU_PROGRAM_MAP(m68k_mem) |
src/mess/drivers/pcw.c
| r9685 | r9686 | |
| 111 | 111 | static WRITE_LINE_DEVICE_HANDLER( pcw_fdc_interrupt ); |
| 112 | 112 | |
| 113 | 113 | // pointer to pcw ram |
| 114 | | unsigned int roller_ram_addr; |
| 115 | 114 | // flag to indicate if boot-program is enabled/disabled |
| 116 | | static int pcw_boot; |
| 117 | | static int pcw_system_status; |
| 118 | | unsigned short roller_ram_offset; |
| 119 | 115 | // code for CPU int type generated when FDC int is triggered |
| 120 | | static int fdc_interrupt_code; |
| 121 | | unsigned char pcw_vdu_video_control_register; |
| 122 | | static int pcw_interrupt_counter; |
| 123 | 116 | |
| 124 | | static UINT8 pcw_banks[4]; |
| 125 | | static unsigned char pcw_bank_force = 0; |
| 126 | 117 | |
| 127 | | static UINT8 pcw_timer_irq_flag; |
| 128 | | static UINT8 pcw_nmi_flag; |
| 129 | 118 | |
| 130 | | static UINT8 pcw_printer_command; |
| 131 | | static UINT8 pcw_printer_data; |
| 132 | | static UINT8 pcw_printer_status; |
| 133 | | static UINT8 pcw_printer_headpos; // non-zero if not at left margin |
| 134 | 119 | |
| 135 | | static UINT16 pcw_kb_scan_row; |
| 136 | 120 | |
| 137 | | static UINT8 mcu_keyboard_data[16]; |
| 138 | | static UINT8 mcu_transmit_reset_seq; |
| 139 | | static UINT8 mcu_transmit_count; |
| 140 | 121 | |
| 141 | | static void pcw_update_interrupt_counter(void) |
| 122 | static void pcw_update_interrupt_counter(pcw_state *state) |
| 142 | 123 | { |
| 143 | 124 | /* never increments past 15! */ |
| 144 | | if (pcw_interrupt_counter==0x0f) |
| 125 | if (state->interrupt_counter==0x0f) |
| 145 | 126 | return; |
| 146 | 127 | |
| 147 | 128 | /* increment count */ |
| 148 | | pcw_interrupt_counter++; |
| 129 | state->interrupt_counter++; |
| 149 | 130 | } |
| 150 | 131 | |
| 151 | 132 | /* PCW uses UPD765 in NON-DMA mode. FDC Ints are connected to /INT or |
| r9685 | r9686 | |
| 162 | 143 | // set/reset INT and NMI lines |
| 163 | 144 | static void pcw_update_irqs(running_machine *machine) |
| 164 | 145 | { |
| 146 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 165 | 147 | // set NMI line, remains set until FDC interrupt type is changed |
| 166 | | if(pcw_nmi_flag != 0) |
| 148 | if(state->nmi_flag != 0) |
| 167 | 149 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE); |
| 168 | 150 | else |
| 169 | 151 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); |
| 170 | 152 | |
| 171 | 153 | // set IRQ line, timer pulses IRQ line, all other devices hold it as necessary |
| 172 | | if(fdc_interrupt_code == 1 && (pcw_system_status & 0x20)) |
| 154 | if(state->fdc_interrupt_code == 1 && (state->system_status & 0x20)) |
| 173 | 155 | { |
| 174 | 156 | cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE); |
| 175 | 157 | return; |
| 176 | 158 | } |
| 177 | 159 | |
| 178 | | if(pcw_timer_irq_flag != 0) |
| 160 | if(state->timer_irq_flag != 0) |
| 179 | 161 | { |
| 180 | 162 | cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE); |
| 181 | 163 | return; |
| r9685 | r9686 | |
| 186 | 168 | |
| 187 | 169 | static TIMER_CALLBACK(pcw_timer_pulse) |
| 188 | 170 | { |
| 189 | | pcw_timer_irq_flag = 0; |
| 171 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 172 | state->timer_irq_flag = 0; |
| 190 | 173 | pcw_update_irqs(machine); |
| 191 | 174 | } |
| 192 | 175 | |
| 193 | 176 | /* callback for 1/300ths of a second interrupt */ |
| 194 | 177 | static TIMER_CALLBACK(pcw_timer_interrupt) |
| 195 | 178 | { |
| 196 | | pcw_update_interrupt_counter(); |
| 179 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 180 | pcw_update_interrupt_counter(state); |
| 197 | 181 | |
| 198 | | pcw_timer_irq_flag = 1; |
| 182 | state->timer_irq_flag = 1; |
| 199 | 183 | pcw_update_irqs(machine); |
| 200 | 184 | timer_set(machine,ATTOTIME_IN_USEC(2),NULL,0,pcw_timer_pulse); |
| 201 | 185 | } |
| r9685 | r9686 | |
| 203 | 187 | /* fdc interrupt callback. set/clear fdc int */ |
| 204 | 188 | static WRITE_LINE_DEVICE_HANDLER( pcw_fdc_interrupt ) |
| 205 | 189 | { |
| 190 | pcw_state *drvstate = device->machine->driver_data<pcw_state>(); |
| 206 | 191 | if (state == CLEAR_LINE) |
| 207 | | pcw_system_status &= ~(1<<5); |
| 192 | drvstate->system_status &= ~(1<<5); |
| 208 | 193 | else |
| 209 | 194 | { |
| 210 | | pcw_system_status |= (1<<5); |
| 211 | | if(fdc_interrupt_code == 0) // NMI is held until interrupt type is changed |
| 212 | | pcw_nmi_flag = 1; |
| 195 | drvstate->system_status |= (1<<5); |
| 196 | if(drvstate->fdc_interrupt_code == 0) // NMI is held until interrupt type is changed |
| 197 | drvstate->nmi_flag = 1; |
| 213 | 198 | } |
| 214 | 199 | } |
| 215 | 200 | |
| r9685 | r9686 | |
| 243 | 228 | |
| 244 | 229 | static READ8_HANDLER(pcw_keyboard_data_r) |
| 245 | 230 | { |
| 246 | | return mcu_keyboard_data[offset]; |
| 231 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 232 | return state->mcu_keyboard_data[offset]; |
| 247 | 233 | } |
| 248 | 234 | |
| 249 | 235 | /* ----------------------------------------------------------------------- |
| r9685 | r9686 | |
| 294 | 280 | |
| 295 | 281 | static void pcw_update_mem(running_machine *machine, int block, int data) |
| 296 | 282 | { |
| 283 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 297 | 284 | /* expansion ram select. |
| 298 | 285 | if block is 0-7, selects internal ram instead for read/write |
| 299 | 286 | */ |
| r9685 | r9686 | |
| 341 | 328 | break; |
| 342 | 329 | } |
| 343 | 330 | |
| 344 | | if (pcw_bank_force & mask) |
| 331 | if (state->bank_force & mask) |
| 345 | 332 | { |
| 346 | 333 | read_bank = data & 0x07; |
| 347 | 334 | } |
| r9685 | r9686 | |
| 357 | 344 | } |
| 358 | 345 | |
| 359 | 346 | /* if boot is active, page in fake ROM */ |
| 360 | | /* if ((pcw_boot) && (block==0)) |
| 347 | /* if ((state->boot) && (block==0)) |
| 361 | 348 | { |
| 362 | 349 | unsigned char *FakeROM; |
| 363 | 350 | |
| r9685 | r9686 | |
| 370 | 357 | /* from Jacob Nevins docs */ |
| 371 | 358 | static int pcw_get_sys_status(running_machine *machine) |
| 372 | 359 | { |
| 373 | | return pcw_interrupt_counter | (input_port_read(machine, "EXTRA") & (0x040 | 0x010)) | (pcw_system_status & 0x20); |
| 360 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 361 | return state->interrupt_counter | (input_port_read(machine, "EXTRA") & (0x040 | 0x010)) | (state->system_status & 0x20); |
| 374 | 362 | } |
| 375 | 363 | |
| 376 | 364 | static READ8_HANDLER(pcw_interrupt_counter_r) |
| 377 | 365 | { |
| 366 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 378 | 367 | int data; |
| 379 | 368 | |
| 380 | 369 | /* from Jacob Nevins docs */ |
| r9685 | r9686 | |
| 382 | 371 | /* get data */ |
| 383 | 372 | data = pcw_get_sys_status(space->machine); |
| 384 | 373 | /* clear int counter */ |
| 385 | | pcw_interrupt_counter = 0; |
| 374 | state->interrupt_counter = 0; |
| 386 | 375 | /* check interrupts */ |
| 387 | 376 | pcw_update_irqs(space->machine); |
| 388 | 377 | /* return data */ |
| r9685 | r9686 | |
| 393 | 382 | |
| 394 | 383 | static WRITE8_HANDLER(pcw_bank_select_w) |
| 395 | 384 | { |
| 385 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 396 | 386 | //LOG(("BANK: %2x %x\n",offset, data)); |
| 397 | | pcw_banks[offset] = data; |
| 387 | state->banks[offset] = data; |
| 398 | 388 | |
| 399 | 389 | pcw_update_mem(space->machine, offset, data); |
| 400 | | //popmessage("RAM Banks: %02x %02x %02x %02x",pcw_banks[0],pcw_banks[1],pcw_banks[2],pcw_banks[3]); |
| 390 | //popmessage("RAM Banks: %02x %02x %02x %02x",state->banks[0],state->banks[1],state->banks[2],state->banks[3]); |
| 401 | 391 | } |
| 402 | 392 | |
| 403 | 393 | static WRITE8_HANDLER(pcw_bank_force_selection_w) |
| 404 | 394 | { |
| 405 | | pcw_bank_force = data; |
| 395 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 396 | state->bank_force = data; |
| 406 | 397 | |
| 407 | | pcw_update_mem(space->machine, 0, pcw_banks[0]); |
| 408 | | pcw_update_mem(space->machine, 1, pcw_banks[1]); |
| 409 | | pcw_update_mem(space->machine, 2, pcw_banks[2]); |
| 410 | | pcw_update_mem(space->machine, 3, pcw_banks[3]); |
| 398 | pcw_update_mem(space->machine, 0, state->banks[0]); |
| 399 | pcw_update_mem(space->machine, 1, state->banks[1]); |
| 400 | pcw_update_mem(space->machine, 2, state->banks[2]); |
| 401 | pcw_update_mem(space->machine, 3, state->banks[3]); |
| 411 | 402 | } |
| 412 | 403 | |
| 413 | 404 | |
| 414 | 405 | static WRITE8_HANDLER(pcw_roller_ram_addr_w) |
| 415 | 406 | { |
| 407 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 416 | 408 | /* |
| 417 | 409 | Address of roller RAM. b7-5: bank (0-7). b4-1: address / 512. */ |
| 418 | 410 | |
| 419 | | roller_ram_addr = (((data>>5) & 0x07)<<14) | |
| 411 | state->roller_ram_addr = (((data>>5) & 0x07)<<14) | |
| 420 | 412 | ((data & 0x01f)<<9); |
| 421 | | LOG(("Roller-RAM: Address set to 0x%05x\n",roller_ram_addr)); |
| 413 | LOG(("Roller-RAM: Address set to 0x%05x\n",state->roller_ram_addr)); |
| 422 | 414 | } |
| 423 | 415 | |
| 424 | 416 | static WRITE8_HANDLER(pcw_pointer_table_top_scan_w) |
| 425 | 417 | { |
| 426 | | roller_ram_offset = data; |
| 427 | | LOG(("Roller-RAM: offset set to 0x%05x\n",roller_ram_offset)); |
| 418 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 419 | state->roller_ram_offset = data; |
| 420 | LOG(("Roller-RAM: offset set to 0x%05x\n",state->roller_ram_offset)); |
| 428 | 421 | } |
| 429 | 422 | |
| 430 | 423 | static WRITE8_HANDLER(pcw_vdu_video_control_register_w) |
| 431 | 424 | { |
| 432 | | pcw_vdu_video_control_register = data; |
| 425 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 426 | state->vdu_video_control_register = data; |
| 433 | 427 | LOG(("Roller-RAM: control reg set to 0x%02x\n",data)); |
| 434 | 428 | } |
| 435 | 429 | |
| 436 | 430 | static WRITE8_HANDLER(pcw_system_control_w) |
| 437 | 431 | { |
| 432 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 438 | 433 | running_device *fdc = space->machine->device("upd765"); |
| 439 | 434 | running_device *speaker = space->machine->device("beep"); |
| 440 | 435 | LOG(("SYSTEM CONTROL: %d\n",data)); |
| r9685 | r9686 | |
| 444 | 439 | /* end bootstrap */ |
| 445 | 440 | case 0: |
| 446 | 441 | { |
| 447 | | pcw_boot = 0; |
| 448 | | pcw_update_mem(space->machine, 0, pcw_banks[0]); |
| 442 | state->boot = 0; |
| 443 | pcw_update_mem(space->machine, 0, state->banks[0]); |
| 449 | 444 | } |
| 450 | 445 | break; |
| 451 | 446 | |
| r9685 | r9686 | |
| 460 | 455 | /* connect fdc interrupt to nmi */ |
| 461 | 456 | case 2: |
| 462 | 457 | { |
| 463 | | int fdc_previous_interrupt_code = fdc_interrupt_code; |
| 458 | int fdc_previous_interrupt_code = state->fdc_interrupt_code; |
| 464 | 459 | |
| 465 | | fdc_interrupt_code = 0; |
| 460 | state->fdc_interrupt_code = 0; |
| 466 | 461 | |
| 467 | 462 | /* previously connected to INT? */ |
| 468 | 463 | if (fdc_previous_interrupt_code == 1) |
| r9685 | r9686 | |
| 479 | 474 | /* connect fdc interrupt to interrupt */ |
| 480 | 475 | case 3: |
| 481 | 476 | { |
| 482 | | int fdc_previous_interrupt_code = fdc_interrupt_code; |
| 477 | int fdc_previous_interrupt_code = state->fdc_interrupt_code; |
| 483 | 478 | |
| 484 | 479 | /* connect to INT */ |
| 485 | | fdc_interrupt_code = 1; |
| 480 | state->fdc_interrupt_code = 1; |
| 486 | 481 | |
| 487 | 482 | /* previously connected to NMI? */ |
| 488 | 483 | if (fdc_previous_interrupt_code == 0) |
| r9685 | r9686 | |
| 490 | 485 | /* yes */ |
| 491 | 486 | |
| 492 | 487 | /* clear nmi interrupt */ |
| 493 | | pcw_nmi_flag = 0; |
| 488 | state->nmi_flag = 0; |
| 494 | 489 | } |
| 495 | 490 | |
| 496 | 491 | /* re-issue interrupt */ |
| r9685 | r9686 | |
| 502 | 497 | /* connect fdc interrupt to neither */ |
| 503 | 498 | case 4: |
| 504 | 499 | { |
| 505 | | int fdc_previous_interrupt_code = fdc_interrupt_code; |
| 500 | int fdc_previous_interrupt_code = state->fdc_interrupt_code; |
| 506 | 501 | |
| 507 | | fdc_interrupt_code = 2; |
| 502 | state->fdc_interrupt_code = 2; |
| 508 | 503 | |
| 509 | 504 | /* previously connected to NMI or INT? */ |
| 510 | 505 | if ((fdc_previous_interrupt_code == 0) || (fdc_previous_interrupt_code == 1)) |
| r9685 | r9686 | |
| 512 | 507 | /* yes */ |
| 513 | 508 | |
| 514 | 509 | /* Clear NMI */ |
| 515 | | pcw_nmi_flag = 0; |
| 510 | state->nmi_flag = 0; |
| 516 | 511 | } |
| 517 | 512 | pcw_update_irqs(space->machine); |
| 518 | 513 | |
| r9685 | r9686 | |
| 676 | 671 | /* TODO: Implement the printer for PCW8256, PCW8512,PCW9256*/ |
| 677 | 672 | static WRITE8_HANDLER(pcw_printer_data_w) |
| 678 | 673 | { |
| 679 | | pcw_printer_data = data; |
| 674 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 675 | state->printer_data = data; |
| 680 | 676 | upi41_master_w(space->machine->device("printer_mcu"),0,data); |
| 681 | 677 | logerror("PRN [0xFC]: Sent command %02x\n",data); |
| 682 | 678 | } |
| 683 | 679 | |
| 684 | 680 | static WRITE8_HANDLER(pcw_printer_command_w) |
| 685 | 681 | { |
| 686 | | pcw_printer_command = data; |
| 682 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 683 | state->printer_command = data; |
| 687 | 684 | upi41_master_w(space->machine->device("printer_mcu"),1,data); |
| 688 | 685 | logerror("PRN [0xFD]: Sent command %02x\n",data); |
| 689 | 686 | } |
| r9685 | r9686 | |
| 736 | 733 | |
| 737 | 734 | static WRITE8_HANDLER(mcu_printer_p2_w) |
| 738 | 735 | { |
| 736 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 739 | 737 | // logerror("PRN: MCU writing %02x to P2\n",data); |
| 740 | 738 | if((data & 0x20) == 0) |
| 741 | | pcw_printer_headpos = 1; // move head |
| 739 | state->printer_headpos = 1; // move head |
| 742 | 740 | if((data & 0x10) == 0) |
| 743 | | pcw_printer_headpos = 0; |
| 741 | state->printer_headpos = 0; |
| 744 | 742 | } |
| 745 | 743 | |
| 746 | 744 | // Paper sensor? |
| r9685 | r9686 | |
| 752 | 750 | // Print head location? (0 if at left margin, otherwise 1) |
| 753 | 751 | static READ8_HANDLER(mcu_printer_t0_r) |
| 754 | 752 | { |
| 755 | | return pcw_printer_headpos; |
| 753 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 754 | return state->printer_headpos; |
| 756 | 755 | } |
| 757 | 756 | |
| 758 | 757 | /* |
| r9685 | r9686 | |
| 762 | 761 | * bit 1: keyboard serial clock |
| 763 | 762 | * bit 0: keyboard serial data |
| 764 | 763 | */ |
| 765 | | static void mcu_transmit_serial(UINT8 bit) |
| 764 | static void mcu_transmit_serial(pcw_state *state, UINT8 bit) |
| 766 | 765 | { |
| 767 | | static UINT8 selected; |
| 768 | | static UINT8 buffer; |
| 769 | 766 | int seq; |
| 770 | 767 | |
| 771 | 768 | /* Keyboard data is sent in serial from the MCU through the keyboard port, to the ASIC |
| 772 | 769 | Sends a string of 12-bit sequences, first 4 bits are the RAM location (from &3ff0), |
| 773 | 770 | then 8 bits for the data to be written there. */ |
| 774 | | seq = mcu_transmit_count % 12; |
| 771 | seq = state->mcu_transmit_count % 12; |
| 775 | 772 | if(seq < 4) |
| 776 | 773 | { |
| 777 | 774 | if(bit == 0) |
| 778 | | selected &= ~(8 >> seq); |
| 775 | state->mcu_selected &= ~(8 >> seq); |
| 779 | 776 | else |
| 780 | | selected |= (8 >> seq); |
| 777 | state->mcu_selected |= (8 >> seq); |
| 781 | 778 | } |
| 782 | 779 | else |
| 783 | 780 | { |
| 784 | 781 | seq -= 4; |
| 785 | 782 | if(bit == 0) |
| 786 | | buffer &= ~(128 >> seq); |
| 783 | state->mcu_buffer &= ~(128 >> seq); |
| 787 | 784 | else |
| 788 | | buffer |= (128 >> seq); |
| 785 | state->mcu_buffer |= (128 >> seq); |
| 789 | 786 | } |
| 790 | | mcu_transmit_count++; |
| 791 | | if(mcu_transmit_count >= 12) |
| 787 | state->mcu_transmit_count++; |
| 788 | if(state->mcu_transmit_count >= 12) |
| 792 | 789 | { |
| 793 | | mcu_keyboard_data[selected] = buffer; |
| 794 | | mcu_transmit_count = 0; |
| 790 | state->mcu_keyboard_data[state->mcu_selected] = state->mcu_buffer; |
| 791 | state->mcu_transmit_count = 0; |
| 795 | 792 | } |
| 796 | 793 | } |
| 797 | 794 | |
| 798 | 795 | static READ8_HANDLER(mcu_kb_scan_r) |
| 799 | 796 | { |
| 800 | | return pcw_kb_scan_row & 0xff; |
| 797 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 798 | return state->kb_scan_row & 0xff; |
| 801 | 799 | } |
| 802 | 800 | |
| 803 | 801 | static WRITE8_HANDLER(mcu_kb_scan_w) |
| 804 | 802 | { |
| 805 | | pcw_kb_scan_row = (pcw_kb_scan_row & 0xff00) | data; |
| 803 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 804 | state->kb_scan_row = (state->kb_scan_row & 0xff00) | data; |
| 806 | 805 | } |
| 807 | 806 | |
| 808 | 807 | static READ8_HANDLER(mcu_kb_scan_high_r) |
| 809 | 808 | { |
| 810 | | return (pcw_kb_scan_row & 0xff00) >> 8; |
| 809 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 810 | return (state->kb_scan_row & 0xff00) >> 8; |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | static WRITE8_HANDLER(mcu_kb_scan_high_w) |
| 814 | 814 | { |
| 815 | | static UINT8 prev; |
| 816 | | |
| 817 | | if((prev & 0x02) && !(data & 0x02)) // bit is transmitted on high-to-low clock transition |
| 815 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 816 | if((state->mcu_prev & 0x02) && !(data & 0x02)) // bit is transmitted on high-to-low clock transition |
| 818 | 817 | { |
| 819 | | mcu_transmit_serial(data & 0x01); |
| 820 | | mcu_transmit_reset_seq = 0; |
| 818 | mcu_transmit_serial(state, data & 0x01); |
| 819 | state->mcu_transmit_reset_seq = 0; |
| 821 | 820 | } |
| 822 | 821 | |
| 823 | | if((prev & 0x01) != (data & 0x01)) // two high->low transitions on the data pin signals the beginning of a new transfer |
| 822 | if((state->mcu_prev & 0x01) != (data & 0x01)) // two high->low transitions on the data pin signals the beginning of a new transfer |
| 824 | 823 | { |
| 825 | | mcu_transmit_reset_seq++; |
| 826 | | if(mcu_transmit_reset_seq > 3) |
| 827 | | mcu_transmit_count = 0; |
| 824 | state->mcu_transmit_reset_seq++; |
| 825 | if(state->mcu_transmit_reset_seq > 3) |
| 826 | state->mcu_transmit_count = 0; |
| 828 | 827 | } |
| 829 | 828 | |
| 830 | | pcw_kb_scan_row = (pcw_kb_scan_row & 0x00ff) | ((data & 0xff) << 8); |
| 831 | | prev = data; |
| 829 | state->kb_scan_row = (state->kb_scan_row & 0x00ff) | ((data & 0xff) << 8); |
| 830 | state->mcu_prev = data; |
| 832 | 831 | } |
| 833 | 832 | |
| 834 | 833 | static READ8_HANDLER(mcu_kb_data_r) |
| 835 | 834 | { |
| 836 | | UINT16 scan_bits = ((pcw_kb_scan_row & 0xf000) >> 4) | (pcw_kb_scan_row & 0xff); |
| 835 | pcw_state *state = space->machine->driver_data<pcw_state>(); |
| 836 | UINT16 scan_bits = ((state->kb_scan_row & 0xf000) >> 4) | (state->kb_scan_row & 0xff); |
| 837 | 837 | int x; |
| 838 | 838 | |
| 839 | 839 | for(x=0;x<12;x++) |
| r9685 | r9686 | |
| 930 | 930 | |
| 931 | 931 | static MACHINE_START( pcw ) |
| 932 | 932 | { |
| 933 | | fdc_interrupt_code = 2; |
| 933 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 934 | state->fdc_interrupt_code = 2; |
| 934 | 935 | } |
| 935 | 936 | |
| 936 | 937 | static MACHINE_RESET( pcw ) |
| 937 | 938 | { |
| 939 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 938 | 940 | UINT8* code = memory_region(machine,"printer_mcu"); |
| 939 | 941 | int x; |
| 940 | 942 | /* ram paging is actually undefined at power-on */ |
| 941 | 943 | |
| 942 | | pcw_bank_force = 0x00; |
| 944 | state->bank_force = 0x00; |
| 943 | 945 | |
| 944 | | pcw_banks[0] = 0x80; |
| 945 | | pcw_banks[1] = 0x81; |
| 946 | | pcw_banks[2] = 0x82; |
| 947 | | pcw_banks[3] = 0x83; |
| 946 | state->banks[0] = 0x80; |
| 947 | state->banks[1] = 0x81; |
| 948 | state->banks[2] = 0x82; |
| 949 | state->banks[3] = 0x83; |
| 948 | 950 | |
| 949 | | pcw_update_mem(machine, 0, pcw_banks[0]); |
| 950 | | pcw_update_mem(machine, 1, pcw_banks[1]); |
| 951 | | pcw_update_mem(machine, 2, pcw_banks[2]); |
| 952 | | pcw_update_mem(machine, 3, pcw_banks[3]); |
| 951 | pcw_update_mem(machine, 0, state->banks[0]); |
| 952 | pcw_update_mem(machine, 1, state->banks[1]); |
| 953 | pcw_update_mem(machine, 2, state->banks[2]); |
| 954 | pcw_update_mem(machine, 3, state->banks[3]); |
| 953 | 955 | |
| 954 | | pcw_boot = 0; // System starts up in bootstrap mode, disabled until it's possible to emulate it. |
| 956 | state->boot = 0; // System starts up in bootstrap mode, disabled until it's possible to emulate it. |
| 955 | 957 | |
| 956 | 958 | /* copy boot code into RAM - yes, it's skipping a step */ |
| 957 | 959 | memset(messram_get_ptr(machine->device("messram")),0x00,messram_get_size(machine->device("messram"))); |
| r9685 | r9686 | |
| 961 | 963 | /* and hack our way past the MCU side of the boot process */ |
| 962 | 964 | code[0x01] = 0x40; |
| 963 | 965 | |
| 964 | | pcw_printer_status = 0xff; |
| 965 | | pcw_printer_command = 0xff; |
| 966 | | pcw_printer_data = 0x00; |
| 967 | | pcw_printer_headpos = 0x00; // bring printer head to left margin |
| 966 | state->printer_status = 0xff; |
| 967 | state->printer_command = 0xff; |
| 968 | state->printer_data = 0x00; |
| 969 | state->printer_headpos = 0x00; // bring printer head to left margin |
| 968 | 970 | } |
| 969 | 971 | |
| 970 | 972 | static DRIVER_INIT(pcw) |
| 971 | 973 | { |
| 974 | pcw_state *state = machine->driver_data<pcw_state>(); |
| 972 | 975 | cpu_set_input_line_vector(machine->device("maincpu"), 0, 0x0ff); |
| 973 | 976 | |
| 974 | 977 | /* lower 4 bits are interrupt counter */ |
| 975 | | pcw_system_status = 0x000; |
| 976 | | pcw_system_status &= ~((1<<6) | (1<<5) | (1<<4)); |
| 978 | state->system_status = 0x000; |
| 979 | state->system_status &= ~((1<<6) | (1<<5) | (1<<4)); |
| 977 | 980 | |
| 978 | | pcw_interrupt_counter = 0; |
| 981 | state->interrupt_counter = 0; |
| 979 | 982 | |
| 980 | | roller_ram_offset = 0; |
| 983 | state->roller_ram_offset = 0; |
| 981 | 984 | |
| 982 | 985 | /* timer interrupt */ |
| 983 | 986 | timer_pulse(machine, ATTOTIME_IN_HZ(300), NULL, 0, pcw_timer_interrupt); |
| r9685 | r9686 | |
| 1191 | 1194 | }; |
| 1192 | 1195 | |
| 1193 | 1196 | /* PCW8256, PCW8512, PCW9256 */ |
| 1194 | | static MACHINE_CONFIG_START( pcw, driver_device ) |
| 1197 | static MACHINE_CONFIG_START( pcw, pcw_state ) |
| 1195 | 1198 | /* basic machine hardware */ |
| 1196 | 1199 | MDRV_CPU_ADD("maincpu", Z80, 4000000) /* clock supplied to chip, but in reality it is 3.4 MHz */ |
| 1197 | 1200 | MDRV_CPU_PROGRAM_MAP(pcw_map) |