src/emu/devcb.c
| r11203 | r11204 | |
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | |
| 365 | |
| 366 | /*------------------------------------------------- |
| 367 | devcb_resolve_read16 - convert a static |
| 368 | 16-bit read definition to a live definition |
| 369 | -------------------------------------------------*/ |
| 370 | |
| 371 | static READ16_DEVICE_HANDLER( trampoline_read_port_to_read16 ) |
| 372 | { |
| 373 | return input_port_read_direct((const input_port_config *)device); |
| 374 | } |
| 375 | |
| 376 | static READ16_DEVICE_HANDLER( trampoline_read_line_to_read16 ) |
| 377 | { |
| 378 | const devcb_resolved_read16 *resolved = (const devcb_resolved_read16 *)device; |
| 379 | return (*resolved->real.readline)((device_t *)resolved->realtarget); |
| 380 | } |
| 381 | |
| 382 | void devcb_resolve_read16(devcb_resolved_read16 *resolved, const devcb_read16 *config, device_t *device) |
| 383 | { |
| 384 | /* reset the resolved structure */ |
| 385 | memset(resolved, 0, sizeof(*resolved)); |
| 386 | |
| 387 | /* input port handlers */ |
| 388 | if (config->type == DEVCB_TYPE_INPUT) |
| 389 | { |
| 390 | resolved->target = device->machine().port(config->tag); |
| 391 | if (resolved->target == NULL) |
| 392 | fatalerror("devcb_resolve_read16: unable to find input port '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 393 | resolved->read = trampoline_read_port_to_read16; |
| 394 | } |
| 395 | |
| 396 | /* address space handlers */ |
| 397 | else if (config->type >= DEVCB_TYPE_MEMORY(AS_PROGRAM) && config->type < DEVCB_TYPE_MEMORY(ADDRESS_SPACES) && config->readspace != NULL) |
| 398 | { |
| 399 | FPTR spacenum = (FPTR)config->type - (FPTR)DEVCB_TYPE_MEMORY(AS_PROGRAM); |
| 400 | |
| 401 | device_t *targetdev = device->siblingdevice(config->tag); |
| 402 | if (targetdev == NULL) |
| 403 | fatalerror("devcb_resolve_read16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 404 | device_memory_interface *memory; |
| 405 | if (!targetdev->interface(memory)) |
| 406 | fatalerror("devcb_resolve_read16: device '%s' (requested by %s '%s') has no memory", config->tag, device->name(), device->tag()); |
| 407 | |
| 408 | resolved->target = targetdev->memory().space(spacenum); |
| 409 | if (resolved->target == NULL) |
| 410 | fatalerror("devcb_resolve_read16: unable to find device '%s' space %d (requested by %s '%s')", config->tag, (int)spacenum, device->name(), device->tag()); |
| 411 | resolved->read = (read16_device_func)config->readspace; |
| 412 | } |
| 413 | |
| 414 | /* device handlers */ |
| 415 | else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->readline != NULL || config->readdevice != NULL)) |
| 416 | { |
| 417 | if (config->type == DEVCB_TYPE_SELF) |
| 418 | resolved->target = device; |
| 419 | else if (config->type == DEVCB_TYPE_DRIVER) |
| 420 | resolved->target = device->machine().driver_data(); |
| 421 | else |
| 422 | if (strcmp(config->tag, DEVICE_SELF_OWNER) == 0) |
| 423 | resolved->target = device->owner(); |
| 424 | else |
| 425 | resolved->target = device->siblingdevice(config->tag); |
| 426 | |
| 427 | if (resolved->target == NULL) |
| 428 | fatalerror("devcb_resolve_read16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 429 | |
| 430 | /* read16 to read16 is direct */ |
| 431 | if (config->readdevice != NULL) |
| 432 | resolved->read = config->readdevice; |
| 433 | |
| 434 | /* read16 to read_line goes through a trampoline */ |
| 435 | else |
| 436 | { |
| 437 | resolved->realtarget = resolved->target; |
| 438 | resolved->real.readline = config->readline; |
| 439 | resolved->target = resolved; |
| 440 | resolved->read = trampoline_read_line_to_read16; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | |
| 446 | /*------------------------------------------------- |
| 447 | devcb_resolve_write16 - convert a static |
| 448 | 16-bit write definition to a live definition |
| 449 | -------------------------------------------------*/ |
| 450 | |
| 451 | static WRITE16_DEVICE_HANDLER( trampoline_write_port_to_write16 ) |
| 452 | { |
| 453 | input_port_write_direct((const input_port_config *)device, data, 0xff); |
| 454 | } |
| 455 | |
| 456 | static WRITE16_DEVICE_HANDLER( trampoline_write_line_to_write16 ) |
| 457 | { |
| 458 | const devcb_resolved_write16 *resolved = (const devcb_resolved_write16 *)device; |
| 459 | (*resolved->real.writeline)((device_t *)resolved->realtarget, (data & 1) ? ASSERT_LINE : CLEAR_LINE); |
| 460 | } |
| 461 | |
| 462 | void devcb_resolve_write16(devcb_resolved_write16 *resolved, const devcb_write16 *config, device_t *device) |
| 463 | { |
| 464 | /* reset the resolved structure */ |
| 465 | memset(resolved, 0, sizeof(*resolved)); |
| 466 | |
| 467 | if (config->type == DEVCB_TYPE_INPUT) |
| 468 | { |
| 469 | resolved->target = device->machine().port(config->tag); |
| 470 | if (resolved->target == NULL) |
| 471 | fatalerror("devcb_resolve_read_line: unable to find input port '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 472 | resolved->write = trampoline_write_port_to_write16; |
| 473 | } |
| 474 | |
| 475 | /* address space handlers */ |
| 476 | else if (config->type >= DEVCB_TYPE_MEMORY(AS_PROGRAM) && config->type < DEVCB_TYPE_MEMORY(ADDRESS_SPACES) && config->writespace != NULL) |
| 477 | { |
| 478 | FPTR spacenum = (FPTR)config->type - (FPTR)DEVCB_TYPE_MEMORY(AS_PROGRAM); |
| 479 | |
| 480 | device_t *targetdev = device->siblingdevice(config->tag); |
| 481 | if (targetdev == NULL) |
| 482 | fatalerror("devcb_resolve_write16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 483 | device_memory_interface *memory; |
| 484 | if (!targetdev->interface(memory)) |
| 485 | fatalerror("devcb_resolve_write16: device '%s' (requested by %s '%s') has no memory", config->tag, device->name(), device->tag()); |
| 486 | |
| 487 | resolved->target = targetdev->memory().space(spacenum); |
| 488 | if (resolved->target == NULL) |
| 489 | fatalerror("devcb_resolve_write16: unable to find device '%s' space %d (requested by %s '%s')", config->tag, (int)spacenum, device->name(), device->tag()); |
| 490 | resolved->write = (write16_device_func)config->writespace; |
| 491 | } |
| 492 | |
| 493 | /* device handlers */ |
| 494 | else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->writeline != NULL || config->writedevice != NULL)) |
| 495 | { |
| 496 | if (config->type == DEVCB_TYPE_SELF) |
| 497 | resolved->target = device; |
| 498 | else if (config->type == DEVCB_TYPE_DRIVER) |
| 499 | resolved->target = device->machine().driver_data(); |
| 500 | else |
| 501 | if (strcmp(config->tag, DEVICE_SELF_OWNER) == 0) |
| 502 | resolved->target = device->owner(); |
| 503 | else |
| 504 | resolved->target = device->siblingdevice(config->tag); |
| 505 | |
| 506 | if (resolved->target == NULL) |
| 507 | fatalerror("devcb_resolve_write16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag()); |
| 508 | |
| 509 | /* write16 to write16 is direct */ |
| 510 | if (config->writedevice != NULL) |
| 511 | resolved->write = config->writedevice; |
| 512 | |
| 513 | /* write16 to write_line goes through a trampoline */ |
| 514 | else |
| 515 | { |
| 516 | resolved->realtarget = resolved->target; |
| 517 | resolved->real.writeline = config->writeline; |
| 518 | resolved->target = resolved; |
| 519 | resolved->write = trampoline_write_line_to_write16; |
| 520 | } |
| 521 | } |
| 522 | } |
src/emu/devcb.h
| r11203 | r11204 | |
| 20 | 20 | write_line_device_func: (device, data) |
| 21 | 21 | read8_device_func: (device, offset) |
| 22 | 22 | write8_device_func: (device, offset, data) |
| 23 | read16_device_func: (device, offset) |
| 24 | write16_device_func: (device, offset, data) |
| 23 | 25 | |
| 24 | 26 | The adapted callback types supported are: |
| 25 | 27 | |
| r11203 | r11204 | |
| 31 | 33 | write8_device_func: (device, offset, data) |
| 32 | 34 | read8_space_func: (space, offset) |
| 33 | 35 | write8_space_func: (space, offset, data) |
| 36 | read16_device_func: (device, offset) |
| 37 | write16_device_func: (device, offset, data) |
| 38 | read16_space_func: (space, offset) |
| 39 | write16_space_func: (space, offset, data) |
| 34 | 40 | |
| 35 | 41 | ***************************************************************************/ |
| 36 | 42 | |
| r11203 | r11204 | |
| 78 | 84 | return (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, 0xff); |
| 79 | 85 | } |
| 80 | 86 | |
| 87 | // static template for a read16 stub function that calls through a given READ16_MEMBER |
| 88 | template<class _Class, UINT16 (_Class::*_Function)(address_space &, offs_t, UINT16)> |
| 89 | UINT16 devcb_stub(device_t *device, offs_t offset) |
| 90 | { |
| 91 | _Class *target = downcast<_Class *>(device); |
| 92 | return (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, 0xffff); |
| 93 | } |
| 94 | |
| 81 | 95 | // static template for a write_line stub function that calls through a given WRITE_LINE_MEMBER |
| 82 | 96 | template<class _Class, void (_Class::*_Function)(int state)> |
| 83 | 97 | void devcb_line_stub(device_t *device, int state) |
| r11203 | r11204 | |
| 94 | 108 | (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, data, 0xff); |
| 95 | 109 | } |
| 96 | 110 | |
| 111 | // static template for a write16 stub function that calls through a given WRITE16_MEMBER |
| 112 | template<class _Class, void (_Class::*_Function)(address_space &, offs_t, UINT16, UINT16)> |
| 113 | void devcb_stub(device_t *device, offs_t offset, UINT16 data) |
| 114 | { |
| 115 | _Class *target = downcast<_Class *>(device); |
| 116 | (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, data, 0xffff); |
| 117 | } |
| 118 | |
| 97 | 119 | #define DEVCB_NULL { DEVCB_TYPE_NULL } |
| 98 | 120 | |
| 99 | 121 | /* standard line or read/write handlers with the calling device passed */ |
| r11203 | r11204 | |
| 261 | 283 | }; |
| 262 | 284 | |
| 263 | 285 | |
| 286 | /* static structure used for device configuration when the desired callback type is a read16_device_func */ |
| 287 | typedef struct _devcb_read16 devcb_read16; |
| 288 | struct _devcb_read16 |
| 289 | { |
| 290 | UINT32 type; /* one of the special DEVCB_TYPE values */ |
| 291 | const char * tag; /* tag of target, where appropriate */ |
| 292 | read_line_device_func readline; /* read line function */ |
| 293 | read16_device_func readdevice; /* read device function */ |
| 294 | read16_space_func readspace; /* read space function */ |
| 295 | }; |
| 264 | 296 | |
| 297 | typedef struct _devcb_resolved_read16 devcb_resolved_read16; |
| 298 | struct _devcb_resolved_read16 |
| 299 | { |
| 300 | const void * target; /* target object */ |
| 301 | read16_device_func read; /* read function */ |
| 302 | const void * realtarget; /* real target object for stubs */ |
| 303 | union |
| 304 | { |
| 305 | read16_device_func readdevice; |
| 306 | read16_space_func readspace; |
| 307 | read_line_device_func readline; |
| 308 | } real; /* real read function for stubs */ |
| 309 | }; |
| 310 | |
| 311 | |
| 312 | /* static structure used for device configuration when the desired callback type is a write16_device_func */ |
| 313 | typedef struct _devcb_write16 devcb_write16; |
| 314 | struct _devcb_write16 |
| 315 | { |
| 316 | UINT32 type; /* one of the special DEVCB_TYPE values */ |
| 317 | const char * tag; /* tag of target, where appropriate */ |
| 318 | write_line_device_func writeline; /* write line function */ |
| 319 | write16_device_func writedevice; /* write device function */ |
| 320 | write16_space_func writespace; /* write space function */ |
| 321 | }; |
| 322 | |
| 323 | typedef struct _devcb_resolved_write16 devcb_resolved_write16; |
| 324 | struct _devcb_resolved_write16 |
| 325 | { |
| 326 | const void * target; /* target object */ |
| 327 | write16_device_func write; /* write function */ |
| 328 | const void * realtarget; /* real target object for stubs */ |
| 329 | union |
| 330 | { |
| 331 | write16_device_func writedevice; |
| 332 | write16_space_func writespace; |
| 333 | write_line_device_func writeline; |
| 334 | } real; /* real write function for stubs */ |
| 335 | }; |
| 336 | |
| 337 | |
| 265 | 338 | /*************************************************************************** |
| 266 | 339 | FUNCTION PROTOTYPES |
| 267 | 340 | ***************************************************************************/ |
| r11203 | r11204 | |
| 281 | 354 | /* convert a static 8-bit write definition to a live definition */ |
| 282 | 355 | void devcb_resolve_write8(devcb_resolved_write8 *resolved, const devcb_write8 *config, device_t *device); |
| 283 | 356 | |
| 357 | /* convert a static 16-bit read definition to a live definition */ |
| 358 | void devcb_resolve_read16(devcb_resolved_read16 *resolved, const devcb_read16 *config, device_t *device); |
| 284 | 359 | |
| 360 | /* convert a static 16-bit write definition to a live definition */ |
| 361 | void devcb_resolve_write16(devcb_resolved_write16 *resolved, const devcb_write16 *config, device_t *device); |
| 285 | 362 | |
| 363 | |
| 364 | |
| 286 | 365 | /*************************************************************************** |
| 287 | 366 | INLINE FUNCTIONS |
| 288 | 367 | ***************************************************************************/ |
| r11203 | r11204 | |
| 310 | 389 | |
| 311 | 390 | |
| 312 | 391 | /*------------------------------------------------- |
| 392 | devcb_call_read16 - call through a |
| 393 | resolved read16 handler |
| 394 | -------------------------------------------------*/ |
| 395 | |
| 396 | INLINE int devcb_call_read16(const devcb_resolved_read16 *resolved, offs_t offset) |
| 397 | { |
| 398 | return (resolved->read != NULL) ? (*resolved->read)((device_t *)resolved->target, offset, 0xffff) : 0; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /*------------------------------------------------- |
| 313 | 403 | devcb_call_write_line - call through a |
| 314 | 404 | resolved write_line handler |
| 315 | 405 | -------------------------------------------------*/ |
| r11203 | r11204 | |
| 332 | 422 | (*resolved->write)((device_t *)resolved->target, offset, data); |
| 333 | 423 | } |
| 334 | 424 | |
| 425 | |
| 335 | 426 | /*------------------------------------------------- |
| 427 | devcb_call_write16 - call through a |
| 428 | resolved write16 handler |
| 429 | -------------------------------------------------*/ |
| 430 | |
| 431 | INLINE void devcb_call_write16(const devcb_resolved_write16 *resolved, offs_t offset, UINT16 data) |
| 432 | { |
| 433 | if (resolved->write != NULL) |
| 434 | (*resolved->write)((device_t *)resolved->target, offset, data, 0xffff); |
| 435 | } |
| 436 | |
| 437 | |
| 438 | /*------------------------------------------------- |
| 336 | 439 | devcb_line_gnd_r - input tied to GND |
| 337 | 440 | -------------------------------------------------*/ |
| 338 | 441 | |
| r11203 | r11204 | |
| 341 | 444 | return 0; |
| 342 | 445 | } |
| 343 | 446 | |
| 447 | |
| 344 | 448 | /*------------------------------------------------- |
| 345 | 449 | devcb_line_vcc_r - input tied to Vcc |
| 346 | 450 | -------------------------------------------------*/ |
src/mess/machine/kb3600.c
| r11203 | r11204 | |
| 5 | 5 | Copyright MESS Team. |
| 6 | 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | |
| 8 | | **********************************************************************/ |
| 8 | *********************************************************************/ |
| 9 | 9 | |
| 10 | 10 | /* |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | - scan timer clock frequency |
| 14 | 15 | - more accurate emulation of real chip |
| 15 | 16 | |
| 16 | 17 | */ |
| 17 | 18 | |
| 18 | | #include "emu.h" |
| 19 | 19 | #include "kb3600.h" |
| 20 | #include "machine/devhelpr.h" |
| 20 | 21 | |
| 21 | | /*************************************************************************** |
| 22 | | TYPE DEFINITIONS |
| 23 | | ***************************************************************************/ |
| 24 | 22 | |
| 25 | | typedef struct _ay3600_t ay3600_t; |
| 26 | | struct _ay3600_t |
| 27 | | { |
| 28 | | devcb_resolved_read_line in_shift_func; |
| 29 | | devcb_resolved_read_line in_control_func; |
| 30 | 23 | |
| 31 | | devcb_resolved_write_line out_data_ready_func; |
| 32 | | devcb_resolved_write_line out_ako_func; |
| 24 | //************************************************************************** |
| 25 | // MACROS / CONSTANTS |
| 26 | //************************************************************************** |
| 33 | 27 | |
| 34 | | int b; /* output buffer */ |
| 35 | | int ako; /* any key down */ |
| 28 | #define LOG 0 |
| 36 | 29 | |
| 37 | | /* timers */ |
| 38 | | emu_timer *scan_timer; /* keyboard scan timer */ |
| 39 | | }; |
| 40 | 30 | |
| 41 | | /*************************************************************************** |
| 42 | | INLINE FUNCTIONS |
| 43 | | ***************************************************************************/ |
| 44 | 31 | |
| 45 | | INLINE ay3600_t *get_safe_token(device_t *device) |
| 32 | //************************************************************************** |
| 33 | // GLOBAL VARIABLES |
| 34 | //************************************************************************** |
| 35 | |
| 36 | // devices |
| 37 | const device_type AY3600 = ay3600_device_config::static_alloc_device_config; |
| 38 | |
| 39 | |
| 40 | |
| 41 | //************************************************************************** |
| 42 | // DEVICE CONFIGURATION |
| 43 | //************************************************************************** |
| 44 | |
| 45 | GENERIC_DEVICE_CONFIG_SETUP(ay3600, "AY-5-3600") |
| 46 | |
| 47 | |
| 48 | //------------------------------------------------- |
| 49 | // device_config_complete - perform any |
| 50 | // operations now that the configuration is |
| 51 | // complete |
| 52 | //------------------------------------------------- |
| 53 | |
| 54 | void ay3600_device_config::device_config_complete() |
| 46 | 55 | { |
| 47 | | assert(device != NULL); |
| 48 | | assert(device->type() == AY3600PRO002); |
| 56 | // inherit a copy of the static data |
| 57 | const ay3600_interface *intf = reinterpret_cast<const ay3600_interface *>(static_config()); |
| 58 | if (intf != NULL) |
| 59 | *static_cast<ay3600_interface *>(this) = *intf; |
| 49 | 60 | |
| 50 | | return (ay3600_t *)downcast<legacy_device_base *>(device)->token(); |
| 61 | // or initialize to defaults if none provided |
| 62 | else |
| 63 | { |
| 64 | memset(&m_in_shift_func, 0, sizeof(m_in_shift_func)); |
| 65 | memset(&m_in_control_func, 0, sizeof(m_in_control_func)); |
| 66 | memset(&m_out_data_ready_func, 0, sizeof(m_out_data_ready_func)); |
| 67 | memset(&m_out_ako_func, 0, sizeof(m_out_ako_func)); |
| 68 | } |
| 51 | 69 | } |
| 52 | 70 | |
| 53 | | INLINE const ay3600_interface *get_interface(device_t *device) |
| 71 | |
| 72 | |
| 73 | //************************************************************************** |
| 74 | // LIVE DEVICE |
| 75 | //************************************************************************** |
| 76 | |
| 77 | //------------------------------------------------- |
| 78 | // ay3600_device - constructor |
| 79 | //------------------------------------------------- |
| 80 | |
| 81 | ay3600_device::ay3600_device(running_machine &_machine, const ay3600_device_config &config) |
| 82 | : device_t(_machine, config), |
| 83 | m_config(config) |
| 54 | 84 | { |
| 55 | | assert(device != NULL); |
| 56 | | assert((device->type() == AY3600PRO002)); |
| 57 | | return (const ay3600_interface *) device->baseconfig().static_config(); |
| 58 | 85 | } |
| 59 | 86 | |
| 60 | | /*************************************************************************** |
| 61 | | IMPLEMENTATION |
| 62 | | ***************************************************************************/ |
| 63 | 87 | |
| 64 | | /*------------------------------------------------- |
| 65 | | TIMER_CALLBACK( ay3600_scan_tick ) |
| 66 | | -------------------------------------------------*/ |
| 88 | //------------------------------------------------- |
| 89 | // device_start - device-specific startup |
| 90 | //------------------------------------------------- |
| 67 | 91 | |
| 68 | | static TIMER_CALLBACK( ay3600_scan_tick ) |
| 92 | void ay3600_device::device_start() |
| 69 | 93 | { |
| 70 | | device_t *device = (device_t *)ptr; |
| 71 | | ay3600_t *ay3600 = get_safe_token(device); |
| 72 | | const ay3600_interface *intf = get_interface(device); |
| 94 | // resolve callbacks |
| 95 | devcb_resolve_read16(&m_in_x_func[0], &m_config.m_in_x0_func, this); |
| 96 | devcb_resolve_read16(&m_in_x_func[1], &m_config.m_in_x1_func, this); |
| 97 | devcb_resolve_read16(&m_in_x_func[2], &m_config.m_in_x2_func, this); |
| 98 | devcb_resolve_read16(&m_in_x_func[3], &m_config.m_in_x3_func, this); |
| 99 | devcb_resolve_read16(&m_in_x_func[4], &m_config.m_in_x4_func, this); |
| 100 | devcb_resolve_read16(&m_in_x_func[5], &m_config.m_in_x5_func, this); |
| 101 | devcb_resolve_read16(&m_in_x_func[6], &m_config.m_in_x6_func, this); |
| 102 | devcb_resolve_read16(&m_in_x_func[7], &m_config.m_in_x7_func, this); |
| 103 | devcb_resolve_read16(&m_in_x_func[8], &m_config.m_in_x8_func, this); |
| 104 | devcb_resolve_read_line(&m_in_shift_func, &m_config.m_in_shift_func, this); |
| 105 | devcb_resolve_read_line(&m_in_control_func, &m_config.m_in_control_func, this); |
| 106 | devcb_resolve_write_line(&m_out_data_ready_func, &m_config.m_out_data_ready_func, this); |
| 107 | devcb_resolve_write_line(&m_out_ako_func, &m_config.m_out_ako_func, this); |
| 73 | 108 | |
| 74 | | int x, y; |
| 109 | // allocate timers |
| 110 | m_scan_timer = timer_alloc(); |
| 111 | m_scan_timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60)); |
| 112 | |
| 113 | // state saving |
| 114 | save_item(NAME(m_b)); |
| 115 | save_item(NAME(m_ako)); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | //------------------------------------------------- |
| 120 | // device_timer - handler timer events |
| 121 | //------------------------------------------------- |
| 122 | |
| 123 | void ay3600_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 124 | { |
| 75 | 125 | int ako = 0; |
| 76 | 126 | |
| 77 | | for (x = 0; x < 9; x++) |
| 127 | for (int x = 0; x < 9; x++) |
| 78 | 128 | { |
| 79 | | UINT16 data = intf->in_y_func(device, x); |
| 129 | UINT16 data = devcb_call_read16(&m_in_x_func[x], 0); |
| 80 | 130 | |
| 81 | | for (y = 0; y < 10; y++) |
| 131 | for (int y = 0; y < 10; y++) |
| 82 | 132 | { |
| 83 | 133 | if (BIT(data, y)) |
| 84 | 134 | { |
| r11203 | r11204 | |
| 92 | 142 | b = 0x100 | b; |
| 93 | 143 | } |
| 94 | 144 | |
| 95 | | b |= (devcb_call_read_line(&ay3600->in_shift_func) << 6); |
| 96 | | b |= (devcb_call_read_line(&ay3600->in_control_func) << 7); |
| 145 | b |= (devcb_call_read_line(&m_in_shift_func) << 6); |
| 146 | b |= (devcb_call_read_line(&m_in_control_func) << 7); |
| 97 | 147 | |
| 98 | | if (ay3600->b != b) |
| 148 | if (m_b != b) |
| 99 | 149 | { |
| 100 | | ay3600->b = b; |
| 150 | m_b = b; |
| 101 | 151 | |
| 102 | | devcb_call_write_line(&ay3600->out_data_ready_func, 1); |
| 152 | devcb_call_write_line(&m_out_data_ready_func, 1); |
| 103 | 153 | return; |
| 104 | 154 | } |
| 105 | 155 | } |
| r11203 | r11204 | |
| 108 | 158 | |
| 109 | 159 | if (!ako) |
| 110 | 160 | { |
| 111 | | ay3600->b = -1; |
| 161 | m_b = -1; |
| 112 | 162 | } |
| 113 | 163 | |
| 114 | | if (ako != ay3600->ako) |
| 164 | if (ako != m_ako) |
| 115 | 165 | { |
| 116 | | devcb_call_write_line(&ay3600->out_ako_func, ako); |
| 117 | | ay3600->ako = ako; |
| 166 | devcb_call_write_line(&m_out_ako_func, ako); |
| 167 | m_ako = ako; |
| 118 | 168 | } |
| 119 | 169 | } |
| 120 | 170 | |
| 121 | | /*------------------------------------------------- |
| 122 | | ay3600_b_r - keyboard data read |
| 123 | | -------------------------------------------------*/ |
| 124 | 171 | |
| 125 | | UINT16 ay3600_b_r(device_t *device) |
| 172 | //------------------------------------------------- |
| 173 | // b_r - |
| 174 | //------------------------------------------------- |
| 175 | |
| 176 | UINT16 ay3600_device::b_r() |
| 126 | 177 | { |
| 127 | | ay3600_t *ay3600 = get_safe_token(device); |
| 178 | UINT16 data = m_b; |
| 128 | 179 | |
| 129 | | UINT16 data = ay3600->b; |
| 180 | devcb_call_write_line(&m_out_data_ready_func, 0); |
| 130 | 181 | |
| 131 | | devcb_call_write_line(&ay3600->out_data_ready_func, 0); |
| 132 | | |
| 133 | 182 | return data; |
| 134 | 183 | } |
| 135 | | |
| 136 | | /*------------------------------------------------- |
| 137 | | DEVICE_START( ay3600 ) |
| 138 | | -------------------------------------------------*/ |
| 139 | | |
| 140 | | static DEVICE_START( ay3600 ) |
| 141 | | { |
| 142 | | ay3600_t *ay3600 = get_safe_token(device); |
| 143 | | const ay3600_interface *intf = get_interface(device); |
| 144 | | |
| 145 | | /* resolve callbacks */ |
| 146 | | devcb_resolve_read_line(&ay3600->in_shift_func, &intf->in_shift_func, device); |
| 147 | | devcb_resolve_read_line(&ay3600->in_control_func, &intf->in_control_func, device); |
| 148 | | devcb_resolve_write_line(&ay3600->out_data_ready_func, &intf->out_data_ready_func, device); |
| 149 | | devcb_resolve_write_line(&ay3600->out_ako_func, &intf->out_ako_func, device); |
| 150 | | |
| 151 | | /* create the timers */ |
| 152 | | ay3600->scan_timer = device->machine().scheduler().timer_alloc(FUNC(ay3600_scan_tick), (void *)device); |
| 153 | | ay3600->scan_timer->adjust(attotime::zero, 0, attotime::from_hz(60)); |
| 154 | | |
| 155 | | /* register for state saving */ |
| 156 | | device->save_item(NAME(ay3600->b)); |
| 157 | | device->save_item(NAME(ay3600->ako)); |
| 158 | | } |
| 159 | | |
| 160 | | /*------------------------------------------------- |
| 161 | | DEVICE_GET_INFO( ay3600pro002 ) |
| 162 | | -------------------------------------------------*/ |
| 163 | | |
| 164 | | DEVICE_GET_INFO( ay3600pro002 ) |
| 165 | | { |
| 166 | | switch (state) |
| 167 | | { |
| 168 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 169 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ay3600_t); break; |
| 170 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 171 | | |
| 172 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 173 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ay3600); break; |
| 174 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 175 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 176 | | |
| 177 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 178 | | case DEVINFO_STR_NAME: strcpy(info->s, "GI AY-5-3600-PRO-002"); break; |
| 179 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "GI AY-5-3600"); break; |
| 180 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 181 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 182 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 183 | | } |
| 184 | | } |
| 185 | | |
| 186 | | DEFINE_LEGACY_DEVICE(AY3600PRO002, ay3600pro002); |
src/mess/machine/kb3600.h
| r11203 | r11204 | |
| 52 | 52 | |
| 53 | 53 | **********************************************************************/ |
| 54 | 54 | |
| 55 | #pragma once |
| 56 | |
| 55 | 57 | #ifndef __AY3600__ |
| 56 | 58 | #define __AY3600__ |
| 57 | 59 | |
| 58 | | #include "devcb.h" |
| 60 | #include "emu.h" |
| 59 | 61 | |
| 60 | | /*************************************************************************** |
| 61 | | MACROS / CONSTANTS |
| 62 | | ***************************************************************************/ |
| 63 | 62 | |
| 64 | | DECLARE_LEGACY_DEVICE(AY3600PRO002, ay3600pro002); |
| 65 | 63 | |
| 66 | | #define MCFG_AY3600PRO002_ADD(_tag, _intf) \ |
| 67 | | MCFG_DEVICE_ADD(_tag, AY3600PRO002, 0) \ |
| 68 | | MCFG_DEVICE_CONFIG(_intf) |
| 64 | //************************************************************************** |
| 65 | // INTERFACE CONFIGURATION MACROS |
| 66 | //************************************************************************** |
| 69 | 67 | |
| 68 | #define MCFG_AY3600_ADD(_tag, _clock, _config) \ |
| 69 | MCFG_DEVICE_ADD(_tag, AY3600, _clock) \ |
| 70 | MCFG_DEVICE_CONFIG(_config) |
| 71 | |
| 72 | |
| 70 | 73 | #define AY3600_INTERFACE(name) \ |
| 71 | 74 | const ay3600_interface (name) = |
| 72 | 75 | |
| 73 | | typedef UINT16 (*ay3600_y_r)(device_t *device, int x); |
| 74 | | #define AY3600_Y_READ(name) UINT16 name(device_t *device, int x) |
| 75 | 76 | |
| 76 | | /*************************************************************************** |
| 77 | | TYPE DEFINITIONS |
| 78 | | ***************************************************************************/ |
| 79 | 77 | |
| 80 | | typedef struct _ay3600_interface ay3600_interface; |
| 81 | | struct _ay3600_interface |
| 78 | //************************************************************************** |
| 79 | // TYPE DEFINITIONS |
| 80 | //************************************************************************** |
| 81 | |
| 82 | // ======================> ay3600_interface |
| 83 | |
| 84 | struct ay3600_interface |
| 82 | 85 | { |
| 83 | | ay3600_y_r in_y_func; |
| 86 | devcb_read16 m_in_x0_func; |
| 87 | devcb_read16 m_in_x1_func; |
| 88 | devcb_read16 m_in_x2_func; |
| 89 | devcb_read16 m_in_x3_func; |
| 90 | devcb_read16 m_in_x4_func; |
| 91 | devcb_read16 m_in_x5_func; |
| 92 | devcb_read16 m_in_x6_func; |
| 93 | devcb_read16 m_in_x7_func; |
| 94 | devcb_read16 m_in_x8_func; |
| 84 | 95 | |
| 85 | | devcb_read_line in_shift_func; |
| 86 | | devcb_read_line in_control_func; |
| 96 | devcb_read_line m_in_shift_func; |
| 97 | devcb_read_line m_in_control_func; |
| 87 | 98 | |
| 88 | | /* this gets called for every change of the DATA READY pin */ |
| 89 | | devcb_write_line out_data_ready_func; |
| 99 | devcb_write_line m_out_data_ready_func; |
| 100 | devcb_write_line m_out_ako_func; |
| 101 | }; |
| 90 | 102 | |
| 91 | | /* this gets called for every change of the AKO pin */ |
| 92 | | devcb_write_line out_ako_func; |
| 103 | |
| 104 | // ======================> ay3600_device_config |
| 105 | |
| 106 | class ay3600_device_config : public device_config, |
| 107 | public ay3600_interface |
| 108 | { |
| 109 | friend class ay3600_device; |
| 110 | |
| 111 | // construction/destruction |
| 112 | ay3600_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 113 | |
| 114 | public: |
| 115 | // allocators |
| 116 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 117 | virtual device_t *alloc_device(running_machine &machine) const; |
| 118 | |
| 119 | protected: |
| 120 | // device_config overrides |
| 121 | virtual void device_config_complete(); |
| 93 | 122 | }; |
| 94 | 123 | |
| 95 | | /*************************************************************************** |
| 96 | | PROTOTYPES |
| 97 | | ***************************************************************************/ |
| 98 | | /* data read */ |
| 99 | | UINT16 ay3600_b_r(device_t *device); |
| 100 | 124 | |
| 125 | // ======================> ay3600_device |
| 126 | |
| 127 | class ay3600_device : public device_t |
| 128 | { |
| 129 | friend class ay3600_device_config; |
| 130 | |
| 131 | // construction/destruction |
| 132 | ay3600_device(running_machine &_machine, const ay3600_device_config &_config); |
| 133 | |
| 134 | public: |
| 135 | UINT16 b_r(); |
| 136 | |
| 137 | protected: |
| 138 | // device-level overrides |
| 139 | virtual void device_start(); |
| 140 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 141 | |
| 142 | private: |
| 143 | devcb_resolved_read16 m_in_x_func[9]; |
| 144 | |
| 145 | devcb_resolved_read_line m_in_shift_func; |
| 146 | devcb_resolved_read_line m_in_control_func; |
| 147 | |
| 148 | devcb_resolved_write_line m_out_data_ready_func; |
| 149 | devcb_resolved_write_line m_out_ako_func; |
| 150 | |
| 151 | int m_b; // output buffer |
| 152 | int m_ako; // any key down |
| 153 | |
| 154 | // timers |
| 155 | emu_timer *m_scan_timer; // keyboard scan timer |
| 156 | |
| 157 | const ay3600_device_config &m_config; |
| 158 | }; |
| 159 | |
| 160 | |
| 161 | // device type definition |
| 162 | extern const device_type AY3600; |
| 163 | |
| 164 | |
| 165 | |
| 101 | 166 | #endif |
src/mess/drivers/bw12.c
| r11203 | r11204 | |
| 585 | 585 | |
| 586 | 586 | /* AY-5-3600-PRO-002 Interface */ |
| 587 | 587 | |
| 588 | | static AY3600_Y_READ( bw2_ay3600_y_r ) |
| 588 | READ_LINE_MEMBER( bw12_state::ay3600_shift_r ) |
| 589 | 589 | { |
| 590 | | UINT16 data = 0; |
| 591 | | |
| 592 | | switch (x) |
| 593 | | { |
| 594 | | case 0: data = input_port_read(device->machine(), "X0"); break; |
| 595 | | case 1: data = input_port_read(device->machine(), "X1"); break; |
| 596 | | case 2: data = input_port_read(device->machine(), "X2"); break; |
| 597 | | case 3: data = input_port_read(device->machine(), "X3"); break; |
| 598 | | case 4: data = input_port_read(device->machine(), "X4"); break; |
| 599 | | case 5: data = input_port_read(device->machine(), "X5"); break; |
| 600 | | case 6: data = input_port_read(device->machine(), "X6"); break; |
| 601 | | case 7: data = input_port_read(device->machine(), "X7"); break; |
| 602 | | case 8: data = input_port_read(device->machine(), "X8"); break; |
| 603 | | } |
| 604 | | |
| 605 | | return data; |
| 590 | return BIT(input_port_read(m_machine, "MODIFIERS"), 0); |
| 606 | 591 | } |
| 607 | 592 | |
| 608 | | static READ_LINE_DEVICE_HANDLER( ay3600_shift_r ) |
| 593 | READ_LINE_MEMBER( bw12_state::ay3600_control_r ) |
| 609 | 594 | { |
| 610 | | return BIT(input_port_read(device->machine(), "MODIFIERS"), 0); |
| 595 | return BIT(input_port_read(m_machine, "MODIFIERS"), 1); |
| 611 | 596 | } |
| 612 | 597 | |
| 613 | | static READ_LINE_DEVICE_HANDLER( ay3600_control_r ) |
| 614 | | { |
| 615 | | return BIT(input_port_read(device->machine(), "MODIFIERS"), 1); |
| 616 | | } |
| 617 | | |
| 618 | 598 | WRITE_LINE_MEMBER( bw12_state::ay3600_data_ready_w ) |
| 619 | 599 | { |
| 620 | 600 | m_key_stb = state; |
| r11203 | r11204 | |
| 623 | 603 | |
| 624 | 604 | if (state) |
| 625 | 605 | { |
| 626 | | UINT16 data = ay3600_b_r(m_kbc); |
| 606 | UINT16 data = m_kbc->b_r(); |
| 627 | 607 | |
| 628 | 608 | m_key_data[0] = BIT(data, 6); |
| 629 | 609 | m_key_data[1] = BIT(data, 3); |
| r11203 | r11204 | |
| 642 | 622 | |
| 643 | 623 | static AY3600_INTERFACE( bw12_ay3600_intf ) |
| 644 | 624 | { |
| 645 | | bw2_ay3600_y_r, /* Y input */ |
| 646 | | DEVCB_LINE(ay3600_shift_r), /* shift */ |
| 647 | | DEVCB_LINE(ay3600_control_r), /* control */ |
| 648 | | DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_data_ready_w), /* data ready */ |
| 649 | | DEVCB_NULL /* any key down */ |
| 625 | DEVCB_INPUT_PORT("X0"), |
| 626 | DEVCB_INPUT_PORT("X1"), |
| 627 | DEVCB_INPUT_PORT("X2"), |
| 628 | DEVCB_INPUT_PORT("X3"), |
| 629 | DEVCB_INPUT_PORT("X4"), |
| 630 | DEVCB_INPUT_PORT("X5"), |
| 631 | DEVCB_INPUT_PORT("X6"), |
| 632 | DEVCB_INPUT_PORT("X7"), |
| 633 | DEVCB_INPUT_PORT("X8"), |
| 634 | DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_shift_r), |
| 635 | DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_control_r), |
| 636 | DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_data_ready_w), |
| 637 | DEVCB_NULL |
| 650 | 638 | }; |
| 651 | 639 | |
| 652 | 640 | /* Machine Initialization */ |
| r11203 | r11204 | |
| 812 | 800 | MCFG_PIA6821_ADD(PIA6821_TAG, pia_intf) |
| 813 | 801 | MCFG_Z80SIO0_ADD(Z80SIO_TAG, XTAL_16MHz/4, sio_intf) |
| 814 | 802 | MCFG_PIT8253_ADD(PIT8253_TAG, pit_intf) |
| 815 | | MCFG_AY3600PRO002_ADD(AY3600_TAG, bw12_ay3600_intf) |
| 803 | MCFG_AY3600_ADD(AY3600PRO002_TAG, 0, bw12_ay3600_intf) |
| 816 | 804 | |
| 817 | 805 | /* printer */ |
| 818 | 806 | MCFG_CENTRONICS_ADD(CENTRONICS_TAG, bw12_centronics_intf) |