src/mess/audio/upd1771.c
| r0 | r6977 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | NEC uPD1771 |
| 4 | |
| 5 | **********************************************************************/ |
| 6 | |
| 7 | #include "sndintrf.h" |
| 8 | #include "streams.h" |
| 9 | #include "upd1771.h" |
| 10 | |
| 11 | |
| 12 | #define LOG 1 |
| 13 | |
| 14 | #define MAX_PACKET_SIZE 10 |
| 15 | |
| 16 | |
| 17 | typedef struct _upd1771_state upd1771_state; |
| 18 | struct _upd1771_state |
| 19 | { |
| 20 | sound_stream *channel; |
| 21 | devcb_resolved_write_line ack_out_func; |
| 22 | emu_timer *timer; |
| 23 | |
| 24 | UINT8 packet[MAX_PACKET_SIZE]; |
| 25 | UINT8 index; |
| 26 | UINT8 expected_bytes; |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | INLINE upd1771_state *get_safe_token(const device_config *device) |
| 31 | { |
| 32 | assert(device != NULL); |
| 33 | assert(device->token != NULL); |
| 34 | assert(device->type == SOUND); |
| 35 | assert(sound_get_type(device) == SOUND_UPD1771C); |
| 36 | return (upd1771_state *)device->token; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | WRITE8_DEVICE_HANDLER( upd1771_w ) |
| 41 | { |
| 42 | upd1771_state *state = get_safe_token( device ); |
| 43 | |
| 44 | if (LOG) |
| 45 | logerror( "upd1771_w: received byte 0x%02x\n", data ); |
| 46 | |
| 47 | state->packet[ state->index ] = data; |
| 48 | state->index = ( state->index + 1 ) % MAX_PACKET_SIZE; |
| 49 | |
| 50 | devcb_call_write_line( &state->ack_out_func, 0 ); |
| 51 | |
| 52 | /* Trigger ACK after 512??? cycles */ |
| 53 | timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 ); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static STREAM_UPDATE( upd1771c_update ) |
| 58 | { |
| 59 | // upd1771_state *state = (upd1771_state *)param; |
| 60 | stream_sample_t *buffer = outputs[0]; |
| 61 | |
| 62 | while ( samples > 0 ) |
| 63 | { |
| 64 | *buffer = 0; |
| 65 | buffer++; |
| 66 | samples--; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static TIMER_CALLBACK( upd1771c_callback ) |
| 72 | { |
| 73 | const device_config *device = (const device_config *)ptr; |
| 74 | upd1771_state *state = get_safe_token( device ); |
| 75 | |
| 76 | devcb_call_write_line( &state->ack_out_func, 1 ); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | static DEVICE_START( upd1771c ) |
| 81 | { |
| 82 | const upd1771_interface *intf = (const upd1771_interface *)device->static_config; |
| 83 | upd1771_state *state = get_safe_token( device ); |
| 84 | int sample_rate = device->clock / 4; |
| 85 | |
| 86 | /* resolve callbacks */ |
| 87 | devcb_resolve_write_line( &state->ack_out_func, &intf->ack_callback, device ); |
| 88 | |
| 89 | state->timer = timer_alloc( device->machine, upd1771c_callback, (void *)device ); |
| 90 | |
| 91 | state->channel = stream_create( device, 0, 1, sample_rate, state, upd1771c_update ); |
| 92 | |
| 93 | state_save_register_device_item_array( device, 0, state->packet ); |
| 94 | state_save_register_device_item(device, 0, state->index ); |
| 95 | state_save_register_device_item(device, 0, state->expected_bytes ); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static DEVICE_RESET( upd1771c ) |
| 100 | { |
| 101 | upd1771_state *state = get_safe_token( device ); |
| 102 | |
| 103 | state->index = 0; |
| 104 | state->expected_bytes = 0; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | DEVICE_GET_INFO( upd1771c ) |
| 109 | { |
| 110 | switch (state) |
| 111 | { |
| 112 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 113 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(upd1771_state); break; |
| 114 | |
| 115 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 116 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( upd1771c ); break; |
| 117 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( upd1771c ); break; |
| 118 | |
| 119 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 120 | case DEVINFO_STR_NAME: strcpy(info->s, "NEC uPD1771C"); break; |
| 121 | case DEVINFO_STR_FAMILY: strcpy(info->s, "NEC uPD1771"); break; |
| 122 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 123 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 124 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MAME & MESS Teams"); break; |
| 125 | } |
| 126 | } |
| 127 | |
src/mess/audio/upd1771.h
| r0 | r6977 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | NEC uPD1771 |
| 4 | |
| 5 | **********************************************************************/ |
| 6 | |
| 7 | #ifndef __UPD1771_H__ |
| 8 | #define __UPD1771_H__ |
| 9 | |
| 10 | #include "devcb.h" |
| 11 | |
| 12 | /*************************************************************************** |
| 13 | TYPE DEFINITIONS |
| 14 | ***************************************************************************/ |
| 15 | |
| 16 | typedef struct _upd1771_interface upd1771_interface; |
| 17 | struct _upd1771_interface |
| 18 | { |
| 19 | devcb_write_line ack_callback; |
| 20 | }; |
| 21 | |
| 22 | |
| 23 | /*************************************************************************** |
| 24 | MACROS / CONSTANTS |
| 25 | ***************************************************************************/ |
| 26 | |
| 27 | #define SOUND_UPD1771C DEVICE_GET_INFO_NAME(upd1771c) |
| 28 | |
| 29 | |
| 30 | /*************************************************************************** |
| 31 | PROTOTYPES |
| 32 | ***************************************************************************/ |
| 33 | |
| 34 | DEVICE_GET_INFO( upd1771c ); |
| 35 | WRITE8_DEVICE_HANDLER( upd1771_w ); |
| 36 | |
| 37 | #endif /* __UPD1771_H__ */ |
src/mess/drivers/scv.c
| r6976 | r6977 | |
| 6 | 6 | ***************************************************************************/ |
| 7 | 7 | |
| 8 | 8 | #include "driver.h" |
| 9 | #include "devcb.h" |
| 9 | 10 | #include "cpu/upd7810/upd7810.h" |
| 10 | 11 | #include "devices/cartslot.h" |
| 12 | #include "audio/upd1771.h" |
| 11 | 13 | |
| 12 | 14 | |
| 13 | 15 | static WRITE8_HANDLER( scv_porta_w ); |
| r6976 | r6977 | |
| 27 | 29 | |
| 28 | 30 | AM_RANGE( 0x2000, 0x3403 ) AM_RAM AM_BASE( &scv_vram ) /* VRAM + 4 registers */ |
| 29 | 31 | |
| 32 | AM_RANGE( 0x3600, 0x37ff ) AM_DEVWRITE( "upd1771c", upd1771_w ) |
| 33 | |
| 30 | 34 | AM_RANGE( 0x8000, 0xff7f ) AM_ROM AM_REGION("cart", 0) |
| 31 | 35 | AM_RANGE( 0xff80, 0xffff ) AM_RAM /* upd7801 internal RAM */ |
| 32 | 36 | ADDRESS_MAP_END |
| r6976 | r6977 | |
| 522 | 526 | } |
| 523 | 527 | |
| 524 | 528 | |
| 529 | static WRITE_LINE_DEVICE_HANDLER( scv_upd1771_ack_w ) |
| 530 | { |
| 531 | cputag_set_input_line(device->machine, "maincpu", UPD7810_INTF1, (state) ? ASSERT_LINE : CLEAR_LINE); |
| 532 | } |
| 533 | |
| 534 | |
| 525 | 535 | static MACHINE_START( scv ) |
| 526 | 536 | { |
| 527 | 537 | scv_vb_timer = timer_alloc( machine, scv_vb_callback, NULL ); |
| r6976 | r6977 | |
| 554 | 564 | |
| 555 | 565 | |
| 556 | 566 | static const UPD7810_CONFIG scv_cpu_config = { TYPE_7801, NULL }; |
| 567 | static const upd1771_interface scv_upd1771c_config = { DEVCB_LINE( scv_upd1771_ack_w ) }; |
| 557 | 568 | |
| 558 | 569 | |
| 559 | 570 | static MACHINE_DRIVER_START( scv ) |
| r6976 | r6977 | |
| 577 | 588 | MDRV_VIDEO_UPDATE( scv ) |
| 578 | 589 | |
| 579 | 590 | /* Sound is generated by UPD1771C clocked at XTAL_6MHz */ |
| 591 | MDRV_SOUND_ADD( "upd1771c", UPD1771C, XTAL_6MHz ) |
| 592 | MDRV_SOUND_CONFIG( scv_upd1771c_config ) |
| 580 | 593 | |
| 581 | 594 | MDRV_CARTSLOT_ADD( "cart" ) |
| 582 | 595 | MDRV_CARTSLOT_EXTENSION_LIST( "bin" ) |
| r6976 | r6977 | |
| 606 | 619 | MDRV_VIDEO_UPDATE( scv ) |
| 607 | 620 | |
| 608 | 621 | /* Sound is generated by UPD1771C clocked at XTAL_6MHz */ |
| 622 | MDRV_SOUND_ADD( "upd1771c", UPD1771C, XTAL_6MHz ) |
| 623 | MDRV_SOUND_CONFIG( scv_upd1771c_config ) |
| 624 | |
| 609 | 625 | MDRV_CARTSLOT_ADD( "cart" ) |
| 610 | 626 | MDRV_CARTSLOT_EXTENSION_LIST( "bin" ) |
| 611 | 627 | MDRV_CARTSLOT_NOT_MANDATORY |