src/mess/audio/cdp1863.c
| r11128 | r11129 | |
| 1 | | /* |
| 2 | | |
| 3 | | TODO: |
| 4 | | |
| 5 | | - what happens if you connect both clocks? |
| 6 | | - convert to sound device when possible |
| 7 | | |
| 8 | | */ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "streams.h" |
| 12 | | #include "audio/cdp1863.h" |
| 13 | | |
| 14 | | #define CDP1863_DEFAULT_LATCH 0x35 |
| 15 | | |
| 16 | | typedef struct _cdp1863_t cdp1863_t; |
| 17 | | struct _cdp1863_t |
| 18 | | { |
| 19 | | const cdp1863_interface *intf; /* interface */ |
| 20 | | |
| 21 | | sound_stream *stream; /* sound output */ |
| 22 | | |
| 23 | | /* sound state */ |
| 24 | | int oe; /* output enable */ |
| 25 | | int latch; /* sound latch */ |
| 26 | | INT16 signal; /* current signal */ |
| 27 | | int incr; /* initial wave state */ |
| 28 | | }; |
| 29 | | |
| 30 | | INLINE cdp1863_t *get_safe_token(device_t *device) |
| 31 | | { |
| 32 | | assert(device != NULL); |
| 33 | | |
| 34 | | return (cdp1863_t *)downcast<legacy_device_base *>(device)->token(); |
| 35 | | } |
| 36 | | |
| 37 | | /* Load Tone Latch */ |
| 38 | | |
| 39 | | WRITE8_DEVICE_HANDLER( cdp1863_str_w ) |
| 40 | | { |
| 41 | | cdp1863_t *cdp1863 = get_safe_token(device); |
| 42 | | double frequency; |
| 43 | | |
| 44 | | cdp1863->latch = data; |
| 45 | | |
| 46 | | if (cdp1863->intf->clock1 > 0) |
| 47 | | { |
| 48 | | /* CLK1 is pre-divided by 4 */ |
| 49 | | frequency = cdp1863->intf->clock1 / 4 / (data + 1) / 2; |
| 50 | | } |
| 51 | | else |
| 52 | | { |
| 53 | | /* CLK2 is pre-divided by 8 */ |
| 54 | | frequency = cdp1863->intf->clock2 / 8 / (data + 1) / 2; |
| 55 | | } |
| 56 | | |
| 57 | | beep_set_frequency(0, frequency); |
| 58 | | } |
| 59 | | |
| 60 | | /* Output Enable */ |
| 61 | | |
| 62 | | void cdp1863_oe_w(device_t *device, int level) |
| 63 | | { |
| 64 | | cdp1863_t *cdp1863 = get_safe_token(device); |
| 65 | | |
| 66 | | cdp1863->oe = level; |
| 67 | | |
| 68 | | beep_set_state(0, level); |
| 69 | | } |
| 70 | | |
| 71 | | #ifdef UNUSED_FUNCTION |
| 72 | | static void cdp1863_sound_update(device_t *device, stream_sample_t **inputs, stream_sample_t **_buffer, int length) |
| 73 | | { |
| 74 | | cdp1863_t *cdp1863 = get_safe_token(device); |
| 75 | | |
| 76 | | INT16 signal = cdp1863->signal; |
| 77 | | stream_sample_t *buffer = _buffer[0]; |
| 78 | | |
| 79 | | memset(buffer, 0, length * sizeof(*buffer)); |
| 80 | | |
| 81 | | if (cdp1863->oe) |
| 82 | | { |
| 83 | | double frequency; |
| 84 | | int rate = device->machine().sample_rate() / 2; |
| 85 | | |
| 86 | | /* get progress through wave */ |
| 87 | | int incr = cdp1863->incr; |
| 88 | | |
| 89 | | if (cdp1863->intf->clock1 > 0) |
| 90 | | { |
| 91 | | /* CLK1 is pre-divided by 4 */ |
| 92 | | frequency = cdp1863->intf->clock1 / 4 / (cdp1863->latch + 1) / 2; |
| 93 | | } |
| 94 | | else |
| 95 | | { |
| 96 | | /* CLK2 is pre-divided by 8 */ |
| 97 | | frequency = cdp1863->intf->clock2 / 8 / (cdp1863->latch + 1) / 2; |
| 98 | | } |
| 99 | | |
| 100 | | if (signal < 0) |
| 101 | | { |
| 102 | | signal = -0x7fff; |
| 103 | | } |
| 104 | | else |
| 105 | | { |
| 106 | | signal = 0x7fff; |
| 107 | | } |
| 108 | | |
| 109 | | while( length-- > 0 ) |
| 110 | | { |
| 111 | | *buffer++ = signal; |
| 112 | | incr -= frequency; |
| 113 | | while( incr < 0 ) |
| 114 | | { |
| 115 | | incr += rate; |
| 116 | | signal = -signal; |
| 117 | | } |
| 118 | | } |
| 119 | | |
| 120 | | /* store progress through wave */ |
| 121 | | cdp1863->incr = incr; |
| 122 | | cdp1863->signal = signal; |
| 123 | | } |
| 124 | | } |
| 125 | | #endif |
| 126 | | |
| 127 | | /* Device Interface */ |
| 128 | | |
| 129 | | static DEVICE_START( cdp1863 ) |
| 130 | | { |
| 131 | | cdp1863_t *cdp1863 = get_safe_token(device); |
| 132 | | |
| 133 | | /* validate arguments */ |
| 134 | | assert(device != NULL); |
| 135 | | assert(device->tag() != NULL); |
| 136 | | |
| 137 | | cdp1863->intf = device->baseconfig().static_config(); |
| 138 | | |
| 139 | | assert(cdp1863->intf != NULL); |
| 140 | | assert((cdp1863->intf->clock1 > 0) || (cdp1863->intf->clock2 > 0)); |
| 141 | | |
| 142 | | cdp1863->oe = 1; |
| 143 | | |
| 144 | | /* register for state saving */ |
| 145 | | device->save_item(NAME(cdp1863->oe)); |
| 146 | | device->save_item(NAME(cdp1863->latch)); |
| 147 | | device->save_item(NAME(cdp1863->signal)); |
| 148 | | device->save_item(NAME(cdp1863->incr)); |
| 149 | | } |
| 150 | | |
| 151 | | static DEVICE_RESET( cdp1863 ) |
| 152 | | { |
| 153 | | cdp1863_t *cdp1863 = get_safe_token(device); |
| 154 | | |
| 155 | | cdp1863->latch = CDP1863_DEFAULT_LATCH; |
| 156 | | } |
| 157 | | |
| 158 | | DEVICE_GET_INFO( cdp1863 ) |
| 159 | | { |
| 160 | | switch (state) |
| 161 | | { |
| 162 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 163 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1863_t); break; |
| 164 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 165 | | |
| 166 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 167 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1863); break; |
| 168 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 169 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cdp1863); break; |
| 170 | | |
| 171 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 172 | | case DEVINFO_STR_NAME: strcpy(info->s, "RCA CDP1863"); break; |
| 173 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "RCA CDP1800"); break; |
| 174 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 175 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 176 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 177 | | } |
| 178 | | } |
| 179 | | |
| 180 | | DEFINE_LEGACY_DEVICE(CDP1863, cdp1863); |