public void x1_010_write_rom(byte ChipID, int ROMSize, int DataStart, int DataLength, byte[] ROMData, int ROMDataStartAddress = 0) { x1_010_state info = X1010Data[ChipID]; if (info.ROMSize != ROMSize) { info.rom = new byte[ROMSize]; // (byte[])realloc(info.rom, ROMSize); info.ROMSize = (uint)ROMSize; for (int i = 0; i < ROMSize; i++) { info.rom[i] = 0xff; } } if (DataStart > ROMSize) { return; } if (DataStart + DataLength > ROMSize) { DataLength = ROMSize - DataStart; } for (int i = 0; i < DataLength; i++) { info.rom[i + DataStart] = ROMData[i + ROMDataStartAddress]; } return; }
/*void seta_sound_enable_w(device_t *device, int data) * { * x1_010_state *info = get_safe_token(device); * info->sound_enable = data; * }*/ /* Use these for 8 bit CPUs */ //READ8_DEVICE_HANDLER( seta_sound_r ) private byte seta_sound_r(byte ChipID, int offset) { //x1_010_state *info = get_safe_token(device); x1_010_state info = X1010Data[ChipID]; //offset ^= info->address; return(info.reg[offset]); }
private void device_stop_x1_010(byte ChipID) { x1_010_state info = X1010Data[ChipID]; //free(info.rom); info.rom = null; return; }
public void x1_010_set_mute_mask(byte ChipID, uint MuteMask) { x1_010_state info = X1010Data[ChipID]; byte CurChn; for (CurChn = 0; CurChn < SETA_NUM_CHANNELS; CurChn++) { info.Muted[CurChn] = (byte)((MuteMask >> CurChn) & 0x01); } return; }
//WRITE8_DEVICE_HANDLER( seta_sound_w ) private void seta_sound_w(byte ChipID, int offset, byte data) { //x1_010_state *info = get_safe_token(device); x1_010_state info = X1010Data[ChipID]; int channel, reg; //offset ^= info->address; channel = offset / 8; // sizeof(X1_010_CHANNEL); reg = offset % 8; // sizeof(X1_010_CHANNEL); if (channel < SETA_NUM_CHANNELS && reg == 0 && (info.reg[offset] & 1) == 0 && (data & 1) != 0) { info.smp_offset[channel] = 0; info.env_offset[channel] = 0; } //LOG_REGISTER_WRITE(("%s: offset %6X : data %2X\n", device->machine().describe_context(), offset, data )); info.reg[offset] = data; }
private void device_reset_x1_010(byte ChipID) { x1_010_state info = X1010Data[ChipID]; for (int i = 0; i < 0x2000; i++) { info.reg[i] = 0; } //memset(info->HI_WORD_BUF, 0, 0x2000); for (int i = 0; i < SETA_NUM_CHANNELS; i++) { info.smp_offset[i] = 0; } for (int i = 0; i < SETA_NUM_CHANNELS; i++) { info.env_offset[i] = 0; } return; }
}; // MAX_CHIPS]; /* * private x1_010_state get_safe_token(device_t device) * { * assert(device != null); * assert(device->type() == X1_010); * return (x1_010_state)downcast<legacy_device_base*>(device)->token(); * } */ /*-------------------------------------------------------------- * generate sound to the mix buffer * --------------------------------------------------------------*/ //static STREAM_UPDATE( seta_update ) private void seta_update(byte ChipID, int[][] outputs, int samples) { //x1_010_state *info = (x1_010_state *)param; x1_010_state info = X1010Data[ChipID]; X1_010_CHANNEL reg; int ch, i, volL, volR, freq, div; int start, end; sbyte data; int env; uint smp_offs, smp_step, env_offs, env_step, delta; // mixer buffer zero clear for (i = 0; i < samples; i++) { outputs[0][i] = 0; outputs[1][i] = 0; } // if( info->sound_enable == 0 ) return; for (ch = 0; ch < SETA_NUM_CHANNELS; ch++) { //reg = (X1_010_CHANNEL)info.reg[ch * 8];// sizeof(X1_010_CHANNEL)]; if ((info.reg[ch * 8 + 0] & 1) != 0 && info.Muted[ch] == 0) // reg.status { // Key On int[] bufL = outputs[0]; int[] bufR = outputs[1]; div = (info.reg[ch * 8 + 0] & 0x80) != 0 ? 1 : 0; if ((info.reg[ch * 8 + 0] & 2) == 0) { // PCM sampling start = info.reg[ch * 8 + 4] * 0x1000; //+4 reg.start end = (0x100 - info.reg[ch * 8 + 5]) * 0x1000; //+5 reg.end volL = ((info.reg[ch * 8 + 1] >> 4) & 0xf) * VOL_BASE; //+1 reg.volume volR = ((info.reg[ch * 8 + 1] >> 0) & 0xf) * VOL_BASE; //+1 reg.volume smp_offs = info.smp_offset[ch]; freq = info.reg[ch * 8 + 2] >> div; //+2 reg.frequency // Meta Fox does write the frequency register, but this is a hack to make it "work" with the current setup // This is broken for Arbalester (it writes 8), but that'll be fixed later. if (freq == 0) { freq = 4; } smp_step = (uint)((float)info.base_clock / 8192.0f * freq * (1 << FREQ_BASE_BITS) / (float)info.rate + 0.5f); if (smp_offs == 0) { //LOG_SOUND(("Play sample %p - %p, channel %X volume %d:%d freq %X step %X offset %X\n", // start, end, ch, volL, volR, freq, smp_step, smp_offs)); } for (i = 0; i < samples; i++) { delta = smp_offs >> FREQ_BASE_BITS; // sample ended? if (start + delta >= end) { info.reg[ch * 8 + 0] &= 0xfe; // ~0x01; // Key off//+0 reg.status break; } data = (sbyte)info.rom[start + delta]; bufL[i] += (data * volL / 256); bufR[i] += (data * volR / 256); smp_offs += smp_step; } info.smp_offset[ch] = smp_offs; } else { // Wave form start = info.reg[ch * 8 + 1] * 128 + 0x1000; smp_offs = info.smp_offset[ch]; freq = ((info.reg[ch * 8 + 3] << 8) + info.reg[ch * 8 + 2]) >> div; smp_step = (uint)((float)info.base_clock / 128.0 / 1024.0 / 4.0 * freq * (1 << FREQ_BASE_BITS) / (float)info.rate + 0.5f); env = info.reg[ch * 8 + 5] * 128; env_offs = info.env_offset[ch]; env_step = (uint)( (float)info.base_clock / 128.0 / 1024.0 / 4.0 * info.reg[ch * 8 + 4] * (1 << ENV_BASE_BITS) / (float)info.rate + 0.5f ); /* Print some more debug info */ if (smp_offs == 0) { //LOG_SOUND(("Play waveform %X, channel %X volume %X freq %4X step %X offset %X\n", //reg->volume, ch, reg->end, freq, smp_step, smp_offs)); } for (i = 0; i < samples; i++) { int vol; delta = env_offs >> ENV_BASE_BITS; // Envelope one shot mode if ((info.reg[ch * 8 + 0] & 4) != 0 && delta >= 0x80) { info.reg[ch * 8 + 0] &= 0xfe; // ~0x01; // Key off break; } vol = info.reg[env + (delta & 0x7f)]; volL = ((vol >> 4) & 0xf) * VOL_BASE; volR = ((vol >> 0) & 0xf) * VOL_BASE; data = (sbyte)info.reg[start + ((smp_offs >> FREQ_BASE_BITS) & 0x7f)]; bufL[i] += (data * volL / 256); bufR[i] += (data * volR / 256); smp_offs += smp_step; env_offs += env_step; } info.smp_offset[ch] = smp_offs; info.env_offset[ch] = env_offs; } } } }