Пример #1
0
void CPU::op_irq() {
  CPU::op_read(regs.pc.d); // dummy read; don't use debugger's read method
  op_io();
  if(!regs.e) op_writestack(regs.pc.b);
  op_writestack(regs.pc.h);
  op_writestack(regs.pc.l);
  op_writestack(regs.e ? (regs.p & ~0x10) : regs.p);
  rd.l = op_read(status.interrupt_vector + 0);
  regs.pc.b = 0x00;
  regs.p.i  = 1;
  regs.p.d  = 0;
  rd.h = op_read(status.interrupt_vector + 1);
  regs.pc.w = rd.w;
}
Пример #2
0
void CPU::op_irq(uint16 vector) {
  op_read(regs.pc.d);
  op_io();
  if(!regs.e) op_writestack(regs.pc.b);
  op_writestack(regs.pc.h);
  op_writestack(regs.pc.l);
  op_writestack(regs.e ? (regs.p & ~0x10) : regs.p);
  rd.l = op_read(vector + 0);
  regs.pc.b = 0x00;
  regs.p.i = 1;
  regs.p.d = 0;
  rd.h = op_read(vector + 1);
  regs.pc.w = rd.w;
}
Пример #3
0
void sCPU::op_irq() {
  op_read(regs.pc.d);
  op_io();
  if(!regs.e) op_writestack(regs.pc.b);
  op_writestack(regs.pc.h);
  op_writestack(regs.pc.l);
  op_writestack(regs.e ? (regs.p & ~0x10) : regs.p);
  rd.l = op_read(status.interrupt_vector + 0);
  regs.pc.b = 0x00;
  regs.p.i  = 1;
  regs.p.d  = 0;
  rd.h = op_read(status.interrupt_vector + 1);
  regs.pc.w = rd.w;
}
Пример #4
0
static int S_OPUS_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer)
{
	int	section;	/* FIXME: handle section changes */
	int	cnt, res, rem;
	opus_int16 *	ptr;

	rem = bytes / stream->info.width;
	if (rem / stream->info.channels <= 0)
		return 0;

	cnt = 0;
	ptr = (opus_int16 *) buffer;
	while (1)
	{
	/* op_read() yields 16-bit output using native endian ordering. returns
	 * the number of samples read per channel on success, or a negative value
	 * on failure. */
		res = op_read((OggOpusFile *)stream->priv, ptr, rem, &section);
		if (res <= 0)
			break;
		cnt += res;
		res *= stream->info.channels;
		rem -= res;
		if (rem <= 0)
			break;
		ptr += res;
	}

	if (res < 0)
		return res;

	cnt *= (stream->info.channels * stream->info.width);
	return cnt;
}
Пример #5
0
void SMPcore::op_read_a_addrr() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    op_io();
    rd = op_read(dp + regs.r[i]);
    regs.a = (this->*op)(regs.a, rd);
}
Пример #6
0
void SMPcore::op_read_a_idpy() {
    dp  = op_readpc();
    op_io();
    sp  = op_readdp(dp + 0) << 0;
    sp |= op_readdp(dp + 1) << 8;
    rd  = op_read(sp + regs.y);
    regs.a = (this->*op)(regs.a, rd);
}
Пример #7
0
template<int op> void SMPcore::op_and1_bit() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    bit = dp >> 13;
    dp &= 0x1fff;
    rd  = op_read(dp);
    regs.p.c = regs.p.c & ((bool)(rd & (1 << bit)) ^ op);
}
Пример #8
0
//immediate, 2-cycle opcodes with I/O cycle will become bus read
//when an IRQ is to be triggered immediately after opcode completion.
//this affects the following opcodes:
//  clc, cld, cli, clv, sec, sed, sei,
//  tax, tay, txa, txy, tya, tyx,
//  tcd, tcs, tdc, tsc, tsx, txs,
//  inc, inx, iny, dec, dex, dey,
//  asl, lsr, rol, ror, nop, xce.
alwaysinline void CPUcore::op_io_irq() {
  if(interrupt_pending()) {
    //modify I/O cycle to bus read cycle, do not increment PC
    op_read(regs.pc.d);
  } else {
    op_io();
  }
}
Пример #9
0
void SMPcore::op_not1_bit() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    bit = dp >> 13;
    dp &= 0x1fff;
    rd  = op_read(dp);
    rd ^= 1 << bit;
    op_write(dp, rd);
}
Пример #10
0
void SMPcore::op_eor1_bit() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    bit = dp >> 13;
    dp &= 0x1fff;
    rd  = op_read(dp);
    op_io();
    regs.p.c = regs.p.c ^ (bool)(rd & (1 << bit));
}
Пример #11
0
error_code sys_fs_fcntl(u32 fd, u32 op, vm::ptr<void> _arg, u32 _size)
{
	sys_fs.trace("sys_fs_fcntl(fd=%d, op=0x%x, arg=*0x%x, size=0x%x)", fd, op, _arg, _size);

	switch (op)
	{
	case 0x8000000A: // Read with offset
	case 0x8000000B: // Write with offset
	{
		const auto arg = vm::static_ptr_cast<lv2_file_op_rw>(_arg);

		if (_size < arg.size())
		{
			return CELL_EINVAL;
		}

		const auto file = idm::get<lv2_file>(fd);

		if (!file)
		{
			return CELL_EBADF;
		}

		if (op == 0x8000000A && file->flags & CELL_FS_O_WRONLY)
		{
			return CELL_EBADF;
		}

		if (op == 0x8000000B && !(file->flags & CELL_FS_O_ACCMODE))
		{
			return CELL_EBADF;
		}

		std::lock_guard<std::mutex> lock(file->mp->mutex);

		const u64 old_pos = file->file.pos();
		const u64 new_pos = file->file.seek(arg->offset);

		arg->out_size = op == 0x8000000A
			? file->op_read(arg->buf, arg->size)
			: file->op_write(arg->buf, arg->size);

		verify(HERE), old_pos == file->file.seek(old_pos);

		arg->out_code = CELL_OK;

		break;
	}
	default:
	{
		sys_fs.todo("sys_fs_fcntl(): Unknown operation 0x%08x (fd=%d, arg=*0x%x, size=0x%x)", op, fd, _arg, _size);
	}
	}

	return CELL_OK;
}
Пример #12
0
int file_input_get(char **in_ptr)
{
	char	*ptr, *tmp_ptr;
	int	rd_len, s1;
	mval	val;
	static unsigned int mbuff_len = BUFF_SIZE;
	unsigned int new_mbuff_len, ret_len;
	static char *mbuff = buff1;

	ESTABLISH_RET(mupip_load_ch, 0);
	ret_len = 0;
	for (;;)
	{	/* one-time only reads if in TP to avoid TPNOTACID, otherwise use untimed reads */
		op_read(&val, dollar_tlevel ? 0: NO_M_TIMEOUT);
		rd_len = val.str.len;
		if ((0 == rd_len) && io_curr_device.in->dollar.zeof)
		{
			REVERT;
			if (io_curr_device.in->dollar.x)
				rts_error(VARLSTCNT(1) ERR_PREMATEOF);
			return -1;
		}
		if (mbuff_len < ret_len + rd_len)
		{
			new_mbuff_len = MAX(ret_len,(2 * mbuff_len));
			tmp_ptr = (char *)malloc(new_mbuff_len);
			if (NULL == tmp_ptr)
			{
				REVERT;
				return -1;
			}
			if (mbuff != buff1)
			{
				memcpy(tmp_ptr, mbuff, (ret_len));
				free (mbuff);
			}
			else
				memcpy(tmp_ptr, buff1, (ret_len));

			mbuff = tmp_ptr;
			mbuff_len = new_mbuff_len;

		}
		memcpy((unsigned char *) (mbuff + ret_len), val.str.addr, rd_len);
		ret_len += rd_len;
		if ( !(io_curr_device.in->dollar.x) )
		{
			*in_ptr = mbuff;
			REVERT;
			return ret_len;
		}
	}
}
Пример #13
0
/*
=================
S_OggOpus_CodecReadStream
=================
*/
int S_OggOpus_CodecReadStream( snd_stream_t *stream, int bytes, void *buffer )
{
	// buffer handling
	int samplesRead, samplesLeft, c;
	opus_int16 *bufPtr;

	// check if input is valid
	if ( !( stream && buffer ) )
	{
		return 0;
	}

	if ( bytes <= 0 )
	{
		return 0;
	}

	samplesRead = 0;
	samplesLeft = bytes / stream->info.channels / stream->info.width;
	bufPtr = buffer;

	if ( samplesLeft <= 0 )
	{
		return 0;
	}

	// cycle until we have the requested or all available bytes read
	while ( -1 )
	{
		// read some samples from the opus codec
		c = op_read( ( OggOpusFile * ) stream->ptr, bufPtr + samplesRead * stream->info.channels, samplesLeft * stream->info.channels, NULL );

		// no more samples are left
		if ( c <= 0 )
		{
			break;
		}

		samplesRead += c;
		samplesLeft -= c;

		// we have enough samples
		if ( samplesLeft <= 0 )
		{
			break;
		}
	}

	return samplesRead * stream->info.channels * stream->info.width;
}
Пример #14
0
int AudioStreamPlaybackOpus::mix(int16_t* p_bufer,int p_frames) {
	if (!playing)
		return 0;

	int total=p_frames;

	while (true) {

		int todo = p_frames;

		if (todo==0 || todo<MIN_MIX) {
			break;
		}

		int ret=op_read(opus_file,(opus_int16*)p_bufer,todo*stream_channels,&current_section);
		if (ret<0) {
			playing = false;
			ERR_EXPLAIN("Error reading Opus File: "+file);
			ERR_BREAK(ret<0);
		} else if (ret==0) { // end of song, reload?
			op_free(opus_file);

			_close_file();

			f=FileAccess::open(file,FileAccess::READ);

			int errv = 0;
			opus_file = op_open_callbacks(f,&_op_callbacks,NULL,0,&errv);
			if (errv!=0) {
				playing=false;
				break; // :(
			}

			if (!has_loop()) {
				playing=false;
				repeats=1;
				break;
			}

			if (loop_restart_time) {
				bool ok = op_pcm_seek(opus_file, (loop_restart_time*osrate)+pre_skip)==0;
				if (!ok) {
					playing=false;
					ERR_PRINT("loop restart time rejected")
				}

				frames_mixed=(loop_restart_time*osrate)+pre_skip;
			} else {
Пример #15
0
uint8 CPU::op_read(uint16 addr) {
  if(status.oam_dma_pending) {
    status.oam_dma_pending = false;
    op_read(addr);
    oam_dma();
  }

  while(status.rdy_line == 0) {
    regs.mdr = bus.read(status.rdy_addr ? status.rdy_addr() : addr);
    add_clocks(12);
  }

  regs.mdr = bus.read(addr);
  add_clocks(12);
  return regs.mdr;
}
Пример #16
0
int CSound::DecodeOpus(int SampleID, const void *pData, unsigned DataSize)
{
	if(SampleID == -1 || SampleID >= NUM_SAMPLES)
		return -1;

	CSample *pSample = &m_aSamples[SampleID];

	OggOpusFile *OpusFile = op_open_memory((const unsigned char *) pData, DataSize, NULL);
	if (OpusFile)
	{
		int NumChannels = op_channel_count(OpusFile, -1);
		int NumSamples = op_pcm_total(OpusFile, -1); // per channel!

		pSample->m_Channels = NumChannels;

		if(pSample->m_Channels > 2)
		{
			dbg_msg("sound/opus", "file is not mono or stereo.");
			return -1;
		}

		pSample->m_pData = (short *)mem_alloc(NumSamples * sizeof(short) * NumChannels, 1);

		int Read;
		int Pos = 0;
		while (Pos < NumSamples)
		{
			Read = op_read(OpusFile, pSample->m_pData + Pos*NumChannels, NumSamples*NumChannels, NULL);
			Pos += Read;
		}

		pSample->m_NumFrames = NumSamples; // ?
		pSample->m_Rate = 48000;
		pSample->m_LoopStart = -1;
		pSample->m_LoopEnd = -1;
		pSample->m_PausedAt = 0;
	}
	else
	{
		dbg_msg("sound/opus", "failed to decode sample");
		return -1;
	}

	return SampleID;
}
Пример #17
0
pcm_data_t OpusInMemoryLoader::get_resource() {
	int op_err;
	// open the opus file
	opus_file_t op_file{op_open_file(path.c_str(), &op_err), opus_deleter};

	if (op_err != 0) {
		throw util::Error{"Could not open: %s", path.c_str()};
	}

	// determine number of channels and number of pcm samples
	auto op_channels = op_channel_count(op_file.get(), -1);
	auto pcm_length = op_pcm_total(op_file.get(), -1);
	log::dbg("Opus channels=%d, pcm_length=%u", op_channels, static_cast<uint32_t>(pcm_length));

	// calculate pcm buffer size depending on the number of channels
	// if the opus file only had one channel, the pcm buffer size must be
	// doubled
	uint32_t length = static_cast<uint32_t>(pcm_length) * 2;
	pcm_data_t buffer(static_cast<size_t>(length), 0);

	// read data from opus file
	int position = 0;
	while (true) {
		int samples_read = op_read(op_file.get(), &buffer.front()+position,
				length-position, nullptr);
		if (samples_read < 0) {
			throw util::Error{"Failed to read from opus file: errorcode=%d", samples_read};
		} else if(samples_read == 0) {
			break;
		}

		position += samples_read * op_channels;
	}

	// convert from mono to stereo
	if (op_channels == 1) {
		for(int i = pcm_length-1; i >= 0; i--) {
			auto value = buffer[i];
			buffer[i*2+1] = value;
			buffer[i*2] = value;
		}
	}

	return std::move(buffer);
}
Пример #18
0
int64 OggOpusReader::Read_(int16 *buffer, int64 frames)
{
 int16 *tr_buffer = buffer;
 int64 tr_count = frames * 2;

 while(tr_count > 0)
 {
  int64 didread = op_read(opfile, tr_buffer, tr_count, NULL);

  if(didread == 0)
   break;

  tr_buffer += didread * 2;
  tr_count -= didread * 2;
 }

 return(frames - (tr_count / 2));
}
Пример #19
0
int op_tfs_file(const FileType type)
{
  int extra_flag = 0;

  if (type == TFS_LARGE_FILE)
  {
    extra_flag = T_LARGE;
  }
  else if (type != TFS_SMALL_FILE)
  {
    printf("unknown type: %d\n", type);
    return TFS_ERROR;
  }

  printf("========== op demo type: tfs %s file ===========\n", type == TFS_LARGE_FILE ? "large" : "small");

  // write
  int ret = op_write(extra_flag);
  print_info("write", ret);

  if (ret != TFS_SUCCESS)
  {
    return ret;
  }

  printf("write tfs file name: %s\n", tfs_name);

  // read
  ret = op_read(extra_flag);
  print_info("read", ret);

  // stat
  ret = op_stat(extra_flag);
  print_info("stat", ret);

  // unlink
  ret = op_unlink(extra_flag);
  print_info("unlink", ret);

  ret = op_unique(extra_flag);
  print_info("unique", ret);

  return ret;
}
Пример #20
0
int main(int argc, char *argv[]) {
    assert(argc == 2);

    op_time = strtol(argv[1], NULL, 10);

    assert(op_time >= 0);

    debug("Hello client! Got %ld.\n", op_time);

    control_queue = get_queue(CONTROL_KEY);
    clients_server_queue = get_queue(CLIENTS_SERVER_KEY);
    server_clients_queue = get_queue(SERVER_CLIENTS_KEY);

    pid = getpid();

    debug("My pid is %ld.\n", pid);

    Mesg msg;
    msg.mesg_type = pid;

    queue_send(control_queue, (char *) &msg);

    char buffer[500];
    while (fgets(buffer, sizeof buffer, stdin) != NULL) {
        char op;
        int n;
        const char *p = buffer;

        sscanf(p, "%c%n", &op, &n);
        p += n;

        switch (op) {
            case 'r': op_read(p); break;
            case 'w': op_write(p); break;
            case 's': op_sum(p); break;
            case 'x': op_swap(p); break;
        }
    }

    msg.op = QUIT;
    queue_send(clients_server_queue, (char *) &msg);

    return 0;
}
Пример #21
0
int
main(int argc, const char *argv[])
{
	const char *file = argv[1];
	int fd;
	struct athregrec a;
	int r;

	if (argc < 2) {
		printf("usage: %s <ahq log>\n", argv[0]);
		exit(127);
	}

	fd = open(file, O_RDONLY);
	if (fd < 0) {
		perror("open"); 
		exit(127);
	}

	while (1) {
		r = read(fd, &a, sizeof(a));
		if (r != sizeof(a))
			break;
		switch (a.op) {
			case OP_READ:
				op_read(&a);
				break;
			case OP_WRITE:
				op_write(&a);
				break;
			case OP_DEVICE:
				op_device(&a);
				break;
			case OP_MARK:
				op_mark(&a);
				break;
			default:
				printf("op: %d; reg: 0x%x; val: 0x%x\n",
				    a.op, a.reg, a.val);
		}
	}
	close(fd);
}
Пример #22
0
static gulong
xmms_opus_op_read (OggOpusFile *of, gchar *buf, gint len, gint bigendian,
                     gint sampsize, gint signd, gint *outbuf)
{
	gulong ret;
	int channels;

	channels = op_channel_count (of, -1);

	do {								 /* FIXME buffer len / sample size */
		//ret = op_read_float (of, (float *)buf, len / sizeof(float), outbuf);
		ret = op_read (of, (opus_int16 *)buf, len / 2, outbuf);
	} while (ret == OP_HOLE);

	/* FIXME bytes from samples_read * channels * sample size */
	//ret = ret * channels * sizeof(float);
	ret = ret * channels * 2;

	return ret;
}
Пример #23
0
error_code sys_fs_read(u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<u64> nread)
{
	sys_fs.trace("sys_fs_read(fd=%d, buf=*0x%x, nbytes=0x%llx, nread=*0x%x)", fd, buf, nbytes, nread);

	if (!buf)
	{
		return CELL_EFAULT;
	}

	const auto file = idm::get<lv2_file>(fd);

	if (!file || file->flags & CELL_FS_O_WRONLY)
	{
		return CELL_EBADF;
	}

	std::lock_guard<std::mutex> lock(file->mp->mutex);

	*nread = file->op_read(buf, nbytes);

	return CELL_OK;
}
JNIEXPORT jint JNICALL Java_com_glester_jopus_JOpusDecodable_jopusRead(JNIEnv* environment, jobject caller, jobject sampleBuffer)
{
	OpusWrapper* opus;
	jclass callerClass;
	jfieldID metaPointerID;
	char* sampleBufferContents;
	opus_int32 samplesRead;
	int sampleBufferCapacity;

	// get wrapper data.
	callerClass	= (*environment)->GetObjectClass(environment, caller);
	metaPointerID	= (*environment)->GetFieldID(environment, callerClass, "wrapperPointer", "J");    
	opus 		= (OpusWrapper*)((*environment)->GetLongField(environment, caller, metaPointerID));
	
	sampleBufferContents = (char*)((*environment)->GetDirectBufferAddress(environment, sampleBuffer));
	sampleBufferCapacity = (*environment)->GetDirectBufferCapacity(environment, sampleBuffer);

	// read.
	samplesRead = op_read(opus->file, sampleBufferContents, sampleBufferCapacity, NULL);
	
	return (jint)samplesRead;
}
Пример #25
0
int file_input_get(char **in_ptr)
{
	char	*ptr;
	int	rd_len, ret_len, s1;
	mval	val;

	ESTABLISH_RET(mupip_load_ch, 0);
	buff1_ptr = buff1_end = buff1;
	ret_len = 0;
	for (;;)
	{
		/* do untimed reads */
		op_read(&val, NO_M_TIMEOUT);
		rd_len = val.str.len;
		if ((0 == rd_len) && io_curr_device.in->dollar.zeof)
		{
			REVERT;
			if (io_curr_device.in->dollar.x)
				rts_error(VARLSTCNT(1) ERR_PREMATEOF);
			return -1;
		}
		ret_len += rd_len;
		if (SIZEOF(buff1) < ret_len)
		{
			REVERT;
			return -1;
		}
		memcpy(buff1_end, val.str.addr, rd_len);
		buff1_end = buff1_end + rd_len;
		if ( !(io_curr_device.in->dollar.x) )
		{
			*in_ptr = buff1_ptr;
			REVERT;
			return ret_len;
		}
	}
}
Пример #26
0
void CPU::op_ld_nn_sp() {
  uint16 addr = op_read(r[PC]++) << 0;
  addr |= op_read(r[PC]++) << 8;
  op_write(addr + 0, r[SP] >> 0);
  op_write(addr + 1, r[SP] >> 8);
}
Пример #27
0
template<unsigned x> void CPU::op_ld_rr_nn() {
  r[x]  = op_read(r[PC]++) << 0;
  r[x] |= op_read(r[PC]++) << 8;
}
Пример #28
0
void CPU::op_ldi_a_hl() {
  r[A] = op_read(r[HL]);
  r[HL]++;
}
Пример #29
0
void CPU::op_ldd_a_hl() {
  r[A] = op_read(r[HL]);
  r[HL]--;
}
Пример #30
0
void CPU::op_cb() {
  uint8 opcode = op_read(r[PC]++);
  (this->*opcode_table_cb[opcode])();
}