src/mess/audio/socrates.c
| r0 | r5362 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | audio/socrates.c |
| 4 | |
| 5 | This handles the two squarewaves (plus the one weird wave) channels |
| 6 | on the V-tech Socrates system 27-0769 ASIC. |
| 7 | |
| 8 | ****************************************************************************/ |
| 9 | |
| 10 | #include "sndintrf.h" |
| 11 | #include "streams.h" |
| 12 | #include "socrates.h" |
| 13 | |
| 14 | typedef struct |
| 15 | { |
| 16 | sound_stream *stream; |
| 17 | UINT8 freq[2]; /* channel 1,2 frequencies */ |
| 18 | UINT8 vol_ch1; /* channel 1 volume */ |
| 19 | UINT8 vol_ch2; /* channel 2 volume */ |
| 20 | UINT8 channel3; /* channel 3 weird register */ |
| 21 | UINT8 state[3]; /* output states for channels 1,2,3 */ |
| 22 | UINT8 accum[3]; /* accumulators for channels 1,2,3 */ |
| 23 | UINT8 DAC_output; /* output */ |
| 24 | } SocratesASIC; |
| 25 | |
| 26 | |
| 27 | INLINE SocratesASIC *get_safe_token(const device_config *device) |
| 28 | { |
| 29 | assert(device != NULL); |
| 30 | assert(device->token != NULL); |
| 31 | assert(device->type == SOUND); |
| 32 | assert(sound_get_type(device) == SOUND_SOCRATES); |
| 33 | return (SocratesASIC *)device->token; |
| 34 | } |
| 35 | |
| 36 | static void socrates_snd_clock(SocratesASIC *chip) /* called once per clock */ |
| 37 | { |
| 38 | int channel; |
| 39 | for (channel = 0; channel < 2; channel++) |
| 40 | { |
| 41 | if (chip->accum[channel] == 0) |
| 42 | { |
| 43 | chip->state[channel] = (chip->state[channel]^0x1); |
| 44 | chip->accum[channel] = chip->freq[channel]; |
| 45 | } |
| 46 | else |
| 47 | chip->accum[channel]--; |
| 48 | } |
| 49 | // handle channel 3 here |
| 50 | chip->DAC_output = (chip->state[0]?(chip->vol_ch1<<3):0); |
| 51 | chip->DAC_output += (chip->state[1]?(chip->vol_ch2<<2):0); |
| 52 | // add channel 3 to dac output here |
| 53 | } |
| 54 | |
| 55 | /************************************* |
| 56 | * |
| 57 | * Stream updater |
| 58 | * |
| 59 | *************************************/ |
| 60 | static STREAM_UPDATE( socrates_snd_pcm_update ) |
| 61 | { |
| 62 | INT32 mix[48000]; |
| 63 | INT32 *mixp; |
| 64 | SocratesASIC *chip = (SocratesASIC *)param; |
| 65 | int i; |
| 66 | |
| 67 | memset(mix, 0, sizeof(mix)); |
| 68 | |
| 69 | mixp = &mix[0]; |
| 70 | for (i = 0; i < samples; i++) |
| 71 | { |
| 72 | socrates_snd_clock(chip); |
| 73 | outputs[0][i] = (((int)chip->DAC_output<<8)|(int)chip->DAC_output); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | |
| 79 | /************************************* |
| 80 | * |
| 81 | * Sound handler start |
| 82 | * |
| 83 | *************************************/ |
| 84 | |
| 85 | static DEVICE_START( socrates_snd ) |
| 86 | { |
| 87 | SocratesASIC *chip = get_safe_token(device); |
| 88 | chip->freq[0] = chip->freq[1] = 0xff; /* channel 1,2 frequency */ |
| 89 | chip->vol_ch1 = 0x01; /* channel 1 volume */ |
| 90 | chip->vol_ch2 = 0x01; /* channel 2 volume */ |
| 91 | chip->channel3 = 0x00; /* channel 3 weird register */ |
| 92 | chip->DAC_output = 0x00; /* output */ |
| 93 | chip->state[0] = chip->state[1] = chip->state[2] = 0; |
| 94 | chip->accum[0] = chip->accum[1] = chip->accum[2] = 0xFF; |
| 95 | chip->stream = stream_create(device, 0, 1, device->clock ? device->clock : device->machine->sample_rate, chip, socrates_snd_pcm_update); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | void socrates_snd_reg0_w(const device_config *device, int data) |
| 100 | { |
| 101 | SocratesASIC *chip = get_safe_token(device); |
| 102 | stream_update(chip->stream); |
| 103 | chip->freq[0] = data; |
| 104 | } |
| 105 | |
| 106 | void socrates_snd_reg1_w(const device_config *device, int data) |
| 107 | { |
| 108 | SocratesASIC *chip = get_safe_token(device); |
| 109 | stream_update(chip->stream); |
| 110 | chip->freq[1] = data; |
| 111 | } |
| 112 | |
| 113 | void socrates_snd_reg2_w(const device_config *device, int data) |
| 114 | { |
| 115 | SocratesASIC *chip = get_safe_token(device); |
| 116 | stream_update(chip->stream); |
| 117 | chip->vol_ch1 = data&0xF; |
| 118 | } |
| 119 | |
| 120 | void socrates_snd_reg3_w(const device_config *device, int data) |
| 121 | { |
| 122 | SocratesASIC *chip = get_safe_token(device); |
| 123 | stream_update(chip->stream); |
| 124 | chip->vol_ch2 = data&0xF; |
| 125 | } |
| 126 | |
| 127 | void socrates_snd_reg4_w(const device_config *device, int data) |
| 128 | { |
| 129 | SocratesASIC *chip = get_safe_token(device); |
| 130 | stream_update(chip->stream); |
| 131 | chip->channel3 = data; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /************************************************************************** |
| 136 | * Generic get_info |
| 137 | **************************************************************************/ |
| 138 | |
| 139 | DEVICE_GET_INFO( socrates_snd ) |
| 140 | { |
| 141 | switch (state) |
| 142 | { |
| 143 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 144 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(SocratesASIC); break; |
| 145 | |
| 146 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 147 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( socrates_snd ); break; |
| 148 | |
| 149 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 150 | case DEVINFO_STR_NAME: strcpy(info->s, "Socrates Sound"); break; |
| 151 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Socrates Sound"); break; |
| 152 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 153 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 154 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Jonathan Gevaryahu and The MESS Team"); break; |
| 155 | } |
| 156 | } |
src/mess/drivers/socrates.c
| r5361 | r5362 | |
| 75 | 75 | #include "driver.h" |
| 76 | 76 | #include "cpu/z80/z80.h" |
| 77 | 77 | #include "socrates.lh" |
| 78 | | //#include "sound/beep.h" |
| 78 | #include "audio/socrates.h" |
| 79 | 79 | |
| 80 | 80 | /* Defines */ |
| 81 | 81 | #undef EMULATE_SPEECH // tries miserably to emulate the speech chip readback. works for the first packet, which causes socrates to crash on the second one. |
| r5361 | r5362 | |
| 608 | 608 | |
| 609 | 609 | static WRITE8_HANDLER(socrates_sound_w) |
| 610 | 610 | { |
| 611 | const device_config *socr_snd = devtag_get_device(space->machine, "soc_snd"); |
| 611 | 612 | switch(offset) |
| 612 | 613 | { |
| 613 | 614 | case 0: |
| 614 | | //beep_set_frequency(channel1, (int)((13982.6)/(data+1))); |
| 615 | socrates_snd_reg0_w(socr_snd, data); |
| 615 | 616 | break; |
| 616 | 617 | case 1: |
| 617 | | //beep_set_frequency(channel2, (int)((13982.6)/(data+1))); |
| 618 | socrates_snd_reg1_w(socr_snd, data); |
| 618 | 619 | break; |
| 619 | 620 | case 2: |
| 620 | | //beep_set_volume(channel1, data/4); |
| 621 | socrates_snd_reg2_w(socr_snd, data); |
| 621 | 622 | break; |
| 622 | 623 | case 3: |
| 623 | | //beep_set_volume(channel2, data/8); |
| 624 | socrates_snd_reg3_w(socr_snd, data); |
| 624 | 625 | break; |
| 625 | 626 | case 4: case 5: case 6: case 7: default: |
| 627 | socrates_snd_reg4_w(socr_snd, data); |
| 626 | 628 | break; |
| 627 | 629 | } |
| 628 | 630 | } |
| r5361 | r5362 | |
| 879 | 881 | MDRV_MACHINE_RESET(socrates) |
| 880 | 882 | |
| 881 | 883 | /* video hardware */ |
| 882 | | //MDRV_DEFAULT_LAYOUT(layout_socrates) |
| 883 | 884 | MDRV_SCREEN_ADD("screen", RASTER) |
| 884 | 885 | MDRV_SCREEN_REFRESH_RATE(60) |
| 885 | 886 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| r5361 | r5362 | |
| 892 | 893 | MDRV_VIDEO_UPDATE(socrates) |
| 893 | 894 | |
| 894 | 895 | /* sound hardware */ |
| 895 | | //MDRV_SPEAKER_STANDARD_MONO("mono") |
| 896 | | //MDRV_SOUND_ADD("beep", BEEP, 0) |
| 897 | | //MDRV_SOUND_ADD("beep2", BEEP, 0) |
| 898 | | //MDRV_SOUND_ADD("soc_snd", SOCRATES, XTAL_21_4772MHz/(512+256)) /* this is correct, as strange as it sounds. */ |
| 899 | | //MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.15) |
| 896 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 897 | MDRV_SOUND_ADD("soc_snd", SOCRATES, XTAL_21_4772MHz/(512+256)) // this is correct, as strange as it sounds. |
| 898 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) |
| 900 | 899 | |
| 901 | | |
| 902 | 900 | MACHINE_DRIVER_END |
| 903 | 901 | |
| 904 | 902 | |
| r5361 | r5362 | |
| 964 | 962 | ******************************************************************************/ |
| 965 | 963 | |
| 966 | 964 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME FLAGS */ |
| 967 | | COMP( 1988, socrates, 0, 0, socrates, socrates, socrates, socrates, "V-tech", "Socrates Educational Video System", GAME_NOT_WORKING ) |
| 968 | | COMP( 1988, socratfc, socrates, 0, socrates, socrates, socrates, socrates, "V-tech", "Socrates SAITOUT", GAME_NOT_WORKING ) |
| 965 | COMP( 1988, socrates, 0, 0, socrates, socrates, socrates, socrates, "V-tech", "Socrates Educational Video System", GAME_IMPERFECT_SOUND ) |
| 966 | COMP( 1988, socratfc, socrates, 0, socrates, socrates, socrates, socrates, "V-tech", "Socrates SAITOUT", GAME_IMPERFECT_SOUND ) |