src/mess/audio/vc4000.c
| r4332 | r4333 | |
| 10 | 10 | #include "includes/vc4000.h" |
| 11 | 11 | |
| 12 | 12 | |
| 13 | | static struct |
| 13 | typedef struct _vc4000_sound vc4000_sound; |
| 14 | struct _vc4000_sound |
| 14 | 15 | { |
| 15 | 16 | sound_stream *channel; |
| 16 | 17 | UINT8 reg[1]; |
| 17 | 18 | int size, pos; |
| 18 | 19 | unsigned level; |
| 19 | | } vc4000_sound= { 0 }; |
| 20 | }; |
| 20 | 21 | |
| 21 | 22 | |
| 23 | static vc4000_sound *get_token(const device_config *device) |
| 24 | { |
| 25 | assert(device != NULL); |
| 26 | assert(sound_get_type(device) == SOUND_VC4000); |
| 27 | return (vc4000_sound *) device->token; |
| 28 | } |
| 22 | 29 | |
| 23 | | void vc4000_soundport_w (running_machine *machine, int offset, int data) |
| 30 | |
| 31 | void vc4000_soundport_w (const device_config *device, int offset, int data) |
| 24 | 32 | { |
| 25 | | stream_update(vc4000_sound.channel); |
| 26 | | vc4000_sound.reg[offset] = data; |
| 33 | vc4000_sound *token = get_token(device); |
| 34 | |
| 35 | stream_update(token->channel); |
| 36 | token->reg[offset] = data; |
| 27 | 37 | switch (offset) |
| 28 | 38 | { |
| 29 | | case 0: |
| 30 | | vc4000_sound.pos = 0; |
| 31 | | vc4000_sound.level = TRUE; |
| 32 | | // frequency 7874/(data+1) |
| 33 | | vc4000_sound.size=machine->sample_rate*(data+1)/7874; |
| 34 | | break; |
| 39 | case 0: |
| 40 | token->pos = 0; |
| 41 | token->level = TRUE; |
| 42 | // frequency 7874/(data+1) |
| 43 | token->size = device->machine->sample_rate * (data + 1) /7874; |
| 44 | break; |
| 35 | 45 | } |
| 36 | 46 | } |
| 37 | 47 | |
| r4332 | r4333 | |
| 44 | 54 | static STREAM_UPDATE( vc4000_update ) |
| 45 | 55 | { |
| 46 | 56 | int i; |
| 57 | vc4000_sound *token = get_token(device); |
| 47 | 58 | stream_sample_t *buffer = outputs[0]; |
| 48 | 59 | |
| 49 | 60 | for (i = 0; i < samples; i++, buffer++) |
| 50 | 61 | { |
| 51 | 62 | *buffer = 0; |
| 52 | | if (vc4000_sound.reg[0] && vc4000_sound.pos <= vc4000_sound.size/2) |
| 63 | if (token->reg[0] && token->pos <= token->size / 2) |
| 53 | 64 | { |
| 54 | 65 | *buffer = 0x7fff; |
| 55 | 66 | } |
| 56 | | if (vc4000_sound.pos <= vc4000_sound.size) |
| 57 | | vc4000_sound.pos++; |
| 58 | | if (vc4000_sound.pos > vc4000_sound.size) |
| 59 | | vc4000_sound.pos = 0; |
| 67 | if (token->pos <= token->size) |
| 68 | token->pos++; |
| 69 | if (token->pos > token->size) |
| 70 | token->pos = 0; |
| 60 | 71 | } |
| 61 | 72 | } |
| 62 | 73 | |
| r4332 | r4333 | |
| 68 | 79 | |
| 69 | 80 | static DEVICE_START(vc4000_sound) |
| 70 | 81 | { |
| 71 | | vc4000_sound.channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, vc4000_update); |
| 82 | vc4000_sound *token = get_token(device); |
| 83 | memset(token, 0, sizeof(*token)); |
| 84 | token->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, vc4000_update); |
| 72 | 85 | } |
| 73 | 86 | |
| 74 | 87 | |
| r4332 | r4333 | |
| 76 | 89 | { |
| 77 | 90 | switch (state) |
| 78 | 91 | { |
| 92 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 93 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(vc4000_sound); break; |
| 94 | |
| 79 | 95 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 80 | 96 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(vc4000_sound); break; |
| 81 | 97 | |