Beispiel #1
0
void wd33c9x_base_device::update_irq()
{
	if (m_regs[AUXILIARY_STATUS] & AUXILIARY_STATUS_INT) {
		m_regs[AUXILIARY_STATUS] &= ~AUXILIARY_STATUS_INT;
		LOGMASKED(LOG_LINES, "%s: Clearing IRQ\n", shortname());
		m_irq_cb(CLEAR_LINE);
	}
	if (!irq_fifo_empty()) {
		m_regs[SCSI_STATUS] = irq_fifo_pop();
		m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_INT;

		const uint8_t cc = (m_regs[COMMAND] & COMMAND_CC);
		if (cc == COMMAND_CC_SELECT_TRANSFER || cc == COMMAND_CC_SELECT_ATN_TRANSFER) {
			switch (m_regs[SCSI_STATUS]) {
			case SCSI_STATUS_DISCONNECT:
				if (!(m_regs[CONTROL] & CONTROL_IDI)) {
					return;
				}
				break;

			case SCSI_STATUS_SELECT_TRANSFER_SUCCESS:
				if ((m_regs[CONTROL] & CONTROL_EDI) && m_mode != MODE_D) {
					return;
				}
				break;
			}
		}

		LOGMASKED(LOG_LINES, "%s: Asserting IRQ - SCSI Status (%02x)\n", shortname(), m_regs[SCSI_STATUS]);
		m_irq_cb(ASSERT_LINE);
	}
}
string Vehicle::fullname(bool halffull) const
{
   string s;
   int words = 0;
   if (heat_>0)
   {
	   s = "Stolen ";
	   words++;
   }
   if (displayscolor())
   {
      s += color_+" ";
	   words++;
   }
   if (myear_!=-1 && words<2)//don't print year if that will make the name too long.
   {
      s += tostring(myear_)+" ";
   }
   if (halffull)
      s += shortname();
   else
      s += longname();

   return s;
}
Beispiel #3
0
void a2232_device::autoconfig_base_address(offs_t address)
{
	if (VERBOSE)
		logerror("%s('%s'): autoconfig_base_address received: 0x%06x\n", shortname(), basetag(), address);

	if (VERBOSE)
		logerror("-> installing a2232\n");

	// stop responding to default autoconfig
	m_slot->m_space->unmap_readwrite(0xe80000, 0xe8007f);

	m_slot->m_space->install_readwrite_handler(address, address + 0x3fff,
		read16_delegate(FUNC(a2232_device::shared_ram_r), this),
		write16_delegate(FUNC(a2232_device::shared_ram_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0x4000, address + 0x4001,
		read16_delegate(FUNC(a2232_device::irq_ack_r), this),
		write16_delegate(FUNC(a2232_device::irq_ack_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0x8000, address + 0x8001,
		read16_delegate(FUNC(a2232_device::reset_low_r), this),
		write16_delegate(FUNC(a2232_device::reset_low_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0xa000, address + 0xa001,
		read16_delegate(FUNC(a2232_device::irq_r), this),
		write16_delegate(FUNC(a2232_device::irq_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0xc000, address + 0xc001,
		read16_delegate(FUNC(a2232_device::reset_high_r), this),
		write16_delegate(FUNC(a2232_device::reset_high_w), this), 0xffff);

	// we're done
	m_slot->cfgout_w(0);
}
Beispiel #4
0
const char* MSVC_LocaleLookup(const char* raw_shortname) {

	/* NULL is used to read locale only so we need to return it too */
	if (raw_shortname == NULL) return NULL;

	std::string shortname(raw_shortname);
	if (shortname == "C") return "C";
	if (shortname == "") return "";

	static std::string last_raw_value = "";
	static std::string last_full_name = "";
	static bool first_use = true;

	if (last_raw_value == shortname) {
		return last_full_name.c_str();
	}

	if (first_use) {
		EnumSystemLocalesA(UpdateLocaleCallback, LCID_SUPPORTED | LCID_ALTERNATE_SORTS);
		first_use = false;
	}

	last_raw_value = shortname;

	if (glb_supported_locales.find(utf8_to_wide(shortname)) != glb_supported_locales.end()) {
		last_full_name = wide_to_utf8(
			glb_supported_locales[utf8_to_wide(shortname)]);
		return last_full_name.c_str();
	}

	/* empty string is system default */
	errorstream << "MSVC_LocaleLookup: unsupported locale: \"" << shortname
				<< "\" switching to system default!" << std::endl;
	return "";
}
Beispiel #5
0
bool wd33c9x_base_device::set_command_length(const uint8_t cc)
{
	const bool eaf = ((m_regs[OWN_ID] & OWN_ID_EAF) != 0);
	bool ret;
	if (eaf && (cc == COMMAND_CC_SELECT_TRANSFER || cc == COMMAND_CC_SELECT_ATN_TRANSFER)) {
		m_command_length &= OWN_ID_CDB_SIZE;
		ret = true;
	}
	else if (eaf && cc == COMMAND_CC_WAIT_SELECT_RECEIVE_DATA) {
		m_command_length = 6;
		m_regs[COMMAND_PHASE] = COMMAND_PHASE_CP_BYTES_1;
		irq_fifo_push(SCSI_STATUS_NEED_COMMAND_SIZE);
		update_irq();
		ret = false;
	}
	else {
		switch (m_regs[CDB_1] >> 5) {
		default:
		case 0: m_command_length = 6;  break;
		case 1: m_command_length = 10; break;
		case 5: m_command_length = 12; break;
		}
		ret = true;
	}
	LOGMASKED(LOG_COMMANDS, "%s: SCSI Command Length %d bytes\n", shortname(), m_command_length);
	return ret;
}
Beispiel #6
0
void wd33c9x_base_device::clear_drq()
{
	if (m_drq_state) {
		LOGMASKED(LOG_LINES, "%s: Clearing DRQ\n", shortname());
		m_drq_state = false;
		m_drq_cb(CLEAR_LINE);
	}
}
Beispiel #7
0
void wd33c9x_base_device::data_fifo_push(const uint8_t data)
{
	if (data_fifo_full()) {
		fatalerror("%s: Data FIFO overflow.\n", shortname());
	}
	m_data_fifo[(m_data_fifo_pos + m_data_fifo_size) % DATA_FIFO_SIZE] = data;
	++m_data_fifo_size;
}
Beispiel #8
0
void wd33c9x_base_device::set_drq()
{
	if (!m_drq_state) {
		LOGMASKED(LOG_LINES, "%s: Asserting DRQ\n", shortname());
		m_drq_state = true;
		m_drq_cb(ASSERT_LINE);
	}
}
Beispiel #9
0
static void onmreg(const void *c, upb_handlers *h) {
  const upb_msgdef *m = upb_handlers_msgdef(h);
  upb_msg_field_iter i;
  UPB_UNUSED(c);

  upb_handlers_setstartmsg(h, textprinter_startmsg, NULL);
  upb_handlers_setendmsg(h, textprinter_endmsg, NULL);

  for(upb_msg_field_begin(&i, m);
      !upb_msg_field_done(&i);
      upb_msg_field_next(&i)) {
    upb_fielddef *f = upb_msg_iter_field(&i);
    upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
    upb_handlerattr_sethandlerdata(&attr, f);
    switch (upb_fielddef_type(f)) {
      case UPB_TYPE_INT32:
        upb_handlers_setint32(h, f, textprinter_putint32, &attr);
        break;
      case UPB_TYPE_INT64:
        upb_handlers_setint64(h, f, textprinter_putint64, &attr);
        break;
      case UPB_TYPE_UINT32:
        upb_handlers_setuint32(h, f, textprinter_putuint32, &attr);
        break;
      case UPB_TYPE_UINT64:
        upb_handlers_setuint64(h, f, textprinter_putuint64, &attr);
        break;
      case UPB_TYPE_FLOAT:
        upb_handlers_setfloat(h, f, textprinter_putfloat, &attr);
        break;
      case UPB_TYPE_DOUBLE:
        upb_handlers_setdouble(h, f, textprinter_putdouble, &attr);
        break;
      case UPB_TYPE_BOOL:
        upb_handlers_setbool(h, f, textprinter_putbool, &attr);
        break;
      case UPB_TYPE_STRING:
      case UPB_TYPE_BYTES:
        upb_handlers_setstartstr(h, f, textprinter_startstr, &attr);
        upb_handlers_setstring(h, f, textprinter_putstr, &attr);
        upb_handlers_setendstr(h, f, textprinter_endstr, &attr);
        break;
      case UPB_TYPE_MESSAGE: {
        const char *name =
            upb_fielddef_istagdelim(f)
                ? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
                : upb_fielddef_name(f);
        upb_handlerattr_sethandlerdata(&attr, name);
        upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr);
        upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr);
        break;
      }
      case UPB_TYPE_ENUM:
        upb_handlers_setint32(h, f, textprinter_putenum, &attr);
        break;
    }
  }
}
Beispiel #10
0
ExportFFmpeg::ExportFFmpeg()
:  ExportPlugin()
{
   mEncFormatCtx = NULL;			// libavformat's context for our output file
   mEncFormatDesc = NULL;			// describes our output file to libavformat
   mEncAudioStream = NULL;			// the output audio stream (may remain NULL)
   mEncAudioCodecCtx = NULL;		// the encoder for the output audio stream
   mEncAudioEncodedBuf = NULL;	// buffer to hold frames encoded by the encoder
   #define MAX_AUDIO_PACKET_SIZE (128 * 1024)
   mEncAudioEncodedBufSiz = 4*MAX_AUDIO_PACKET_SIZE;
   mEncAudioFifoOutBuf = NULL;	// buffer to read _out_ of the FIFO into
   mSampleRate = 0;
   mSupportsUTF8 = true;

   PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg::Destroy()
   int newfmt;
   // Adds export types from the export type list
   for (newfmt = 0; newfmt < FMT_LAST; newfmt++)
   {
      wxString shortname(ExportFFmpegOptions::fmts[newfmt].shortname);
      //Don't hide export types when there's no av-libs, and don't hide FMT_OTHER
      if (newfmt < FMT_OTHER && FFmpegLibsInst->ValidLibsLoaded())
      {
         // Format/Codec support is compiled in?
         AVOutputFormat *avoformat = FFmpegLibsInst->guess_format(shortname.mb_str(), NULL, NULL);
         AVCodec *avcodec = FFmpegLibsInst->avcodec_find_encoder(ExportFFmpegOptions::fmts[newfmt].codecid);
         if (avoformat == NULL || avcodec == NULL)
         {
            ExportFFmpegOptions::fmts[newfmt].compiledIn = false;
            continue;
         }
      }
      int fmtindex = AddFormat() - 1;
      SetFormat(ExportFFmpegOptions::fmts[newfmt].name,fmtindex);
      AddExtension(ExportFFmpegOptions::fmts[newfmt].extension,fmtindex);
      // For some types add other extensions
      switch(newfmt)
      {
      case FMT_M4A:
         AddExtension(wxString(wxT("3gp")),fmtindex);
         AddExtension(wxString(wxT("m4r")),fmtindex);
         AddExtension(wxString(wxT("mp4")),fmtindex);
         break;
      case FMT_WMA2:
         AddExtension(wxString(wxT("asf")),fmtindex);
         AddExtension(wxString(wxT("wmv")),fmtindex);
         break;
      default:
         break;
      }

     SetMaxChannels(ExportFFmpegOptions::fmts[newfmt].maxchannels,fmtindex);
     SetCanMetaData(ExportFFmpegOptions::fmts[newfmt].canmetadata,fmtindex);
     SetDescription(ExportFFmpegOptions::fmts[newfmt].description,fmtindex);
   }
}
Beispiel #11
0
uint8_t wd33c9x_base_device::irq_fifo_pop()
{
	if (irq_fifo_empty()) {
		fatalerror("%s: IRQ FIFO underflow.\n", shortname());
	}
	--m_irq_fifo_size;
	uint8_t ret = m_irq_fifo[m_irq_fifo_pos];
	m_irq_fifo_pos = (m_irq_fifo_pos + 1) % IRQ_FIFO_SIZE;
	return ret;
}
Beispiel #12
0
uint8_t wd33c9x_base_device::data_fifo_pop()
{
	if (data_fifo_empty()) {
		fatalerror("%s: Data FIFO underflow.\n", shortname());
	}
	--m_data_fifo_size;
	uint8_t ret = m_data_fifo[m_data_fifo_pos];
	m_data_fifo_pos = (m_data_fifo_pos + 1) % DATA_FIFO_SIZE;
	return ret;
}
Beispiel #13
0
void
readmach(Machine *m, int init)
{
	int n, i;
	uint64_t a[nelem(m->devsysstat)];
	char buf[32];

	if(m->remote && (m->disable || setjmp(catchalarm))){
		if (m->disable++ >= 5)
			m->disable = 0; /* give it another chance */
		memmove(m->devsysstat, m->prevsysstat, sizeof m->devsysstat);
		memmove(m->netetherstats, m->prevetherstats, sizeof m->netetherstats);
		return;
	}
	snprint(buf, sizeof buf, "%s", m->name);
	if (strcmp(m->name, buf) != 0){
		free(m->name);
		m->name = estrdup(buf);
		free(m->shortname);
		m->shortname = shortname(buf);
		if(display != nil)	/* else we're still initializing */
			eresized(0);
	}
	if(m->remote){
		notify(alarmed);
		alarm(5000);
	}
	if(needswap(init) && loadbuf(m, &m->swapfd) && readswap(m, a))
		memmove(m->devswap, a, sizeof m->devswap);
	if(needstat(init) && loadbuf(m, &m->statsfd)){
		memmove(m->prevsysstat, m->devsysstat, sizeof m->devsysstat);
		memset(m->devsysstat, 0, sizeof m->devsysstat);
		for(n=0; n<m->nproc && readnums(m, nelem(m->devsysstat), a, 0); n++)
			for(i=0; i<nelem(m->devsysstat); i++)
				m->devsysstat[i] += a[i];
	}
	if(needether(init) && loadbuf(m, &m->etherfd) && readnums(m, nelem(m->netetherstats), a, 1)){
		memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats);
		memmove(m->netetherstats, a, sizeof m->netetherstats);
	}
	if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){
		memmove(m->netetherifstats, a, sizeof m->netetherifstats);
	}
	if(needbattery(init) && loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
		memmove(m->batterystats, a, sizeof(m->batterystats));
	if(needbattery(init) && loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0))
		memmove(m->batterystats, a, sizeof(m->batterystats));
	if(needtemp(init) && loadbuf(m, &m->tempfd))
		for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++)
			 m->temp[n] = a[0];
	if(m->remote){
		alarm(0);
		notify(nil);
	}
}
Beispiel #14
0
/* return a vnode number matching targethost */
int findtargethost(char *allnodes, char *targethost)
  {
  int i;
  char *ptr;
  int vnode = 0;

  if ((ptr = strchr(targethost, '/')) != NULL)
    {
    *ptr = '\0';
    ptr++;
    vnode = atoi(ptr);
    }

  for (i = 0; i < numnodes; i++)
    {
    if (!strcmp(allnodes + (i*PBS_MAXNODENAME), targethost))
      {
      if (vnode == 0)
        return(i);

      vnode--;
      }
    else
      {
      /* Sometimes the allnodes will return the FQDN of the host
       and the PBS_NODEFILE will have the short name of the host.
       See if the shortname mataches */
      std::string targetname(targethost);
      std::string the_host(allnodes + (i*PBS_MAXNODENAME));
      std::size_t dot = the_host.find_first_of(".");
      if(dot != std::string::npos)
        {
        the_host[dot] = '\0';
        std::string shortname(the_host.c_str());
        if (shortname.compare(targetname) == 0)
          {
          if (vnode == 0)
            return(i);
          vnode--;
          }
        }
      } 
    }

  if (i == numnodes)
    {
    fprintf(stderr, "%s: %s not found\n", id, targethost);
    tm_finalize();
    exit(1);
    }

  return(-1);
  }
Beispiel #15
0
void buddha_device::autoconfig_base_address(offs_t address)
{
	if (VERBOSE)
		logerror("%s('%s'): autoconfig_base_address received: 0x%06x\n", shortname(), basetag(), address);

	if (VERBOSE)
		logerror("-> installing buddha\n");

	// stop responding to default autoconfig
	m_slot->m_space->unmap_readwrite(0xe80000, 0xe8007f);

	// install autoconfig handler to new location
	m_slot->m_space->install_readwrite_handler(address, address + 0x7f,
		read16_delegate(FUNC(amiga_autoconfig::autoconfig_read), static_cast<amiga_autoconfig *>(this)),
		write16_delegate(FUNC(amiga_autoconfig::autoconfig_write), static_cast<amiga_autoconfig *>(this)), 0xffff);

	// buddha registers
	m_slot->m_space->install_readwrite_handler(address + 0x7fe, address + 0x7ff,
		read16_delegate(FUNC(buddha_device::speed_r), this),
		write16_delegate(FUNC(buddha_device::speed_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0x800, address + 0x8ff,
		read16_delegate(FUNC(buddha_device::ide_0_cs0_r), this),
		write16_delegate(FUNC(buddha_device::ide_0_cs0_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0x900, address + 0x9ff,
		read16_delegate(FUNC(buddha_device::ide_0_cs1_r), this),
		write16_delegate(FUNC(buddha_device::ide_0_cs1_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0xa00, address + 0xaff,
		read16_delegate(FUNC(buddha_device::ide_0_cs0_r), this),
		write16_delegate(FUNC(buddha_device::ide_0_cs0_w), this), 0xffff);

	m_slot->m_space->install_readwrite_handler(address + 0xb00, address + 0xbff,
		read16_delegate(FUNC(buddha_device::ide_0_cs1_r), this),
		write16_delegate(FUNC(buddha_device::ide_0_cs1_w), this), 0xffff);

	m_slot->m_space->install_read_handler(address + 0xf00, address + 0xf3f,
		read16_delegate(FUNC(buddha_device::ide_0_interrupt_r), this), 0xffff);

	m_slot->m_space->install_read_handler(address + 0xf40, address + 0xf7f,
		read16_delegate(FUNC(buddha_device::ide_1_interrupt_r), this), 0xffff);

	m_slot->m_space->install_write_handler(address + 0xfc0, address + 0xfff,
		write16_delegate(FUNC(buddha_device::ide_interrupt_enable_w), this), 0xffff);

	// install access to the rom space
	m_slot->m_space->install_rom(address + 0x1000, address + 0xffff, memregion("bootrom")->base() + 0x1000);

	// we're done
	m_slot->cfgout_w(0);
}
Beispiel #16
0
void wd33c9x_base_device::irq_fifo_push(const uint8_t status)
{
	if (irq_fifo_full()) {
		fatalerror("%s: IRQ FIFO overflow.\n", shortname());
	}
	// Kind of hacky, but don't push duplicate interrupt statuses.
	if (m_irq_fifo_size &&
		m_irq_fifo[(m_irq_fifo_pos + m_irq_fifo_size - 1) % IRQ_FIFO_SIZE] == status) {
		return;
	}
	m_irq_fifo[(m_irq_fifo_pos + m_irq_fifo_size) % IRQ_FIFO_SIZE] = status;
	++m_irq_fifo_size;
}
Beispiel #17
0
void QMLAccess::getStringListKey(QString key){
    GConfItem entry(key);
    QStringList entries = entry.value().toStringList();

    currentListValues.clear();

    for (int var = 0; var < entries.count(); ++var) {
        currentListValues.append(new ListKey(entries.at(var),QString::number(var)));
    }

    m_context->setContextProperty("keyName", shortname(key));
    m_context->setContextProperty("listKeys", QVariant::fromValue(currentListValues));
}
Beispiel #18
0
void dmac_device::autoconfig_base_address(offs_t address)
{
	if (VERBOSE)
		logerror("%s('%s'): autoconfig_base_address received: 0x%06x\n", shortname(), basetag(), address);

	if (!m_configured && m_ram_size > 0)
	{
		if (VERBOSE)
			logerror("-> installing ram (%d bytes)\n", m_ram_size);

		// install access to the ram space
		if (address)
			m_space->install_ram(address, address + (m_ram_size - 1), m_ram);

		// prepare autoconfig for main device
		autoconfig_board_size(BOARD_SIZE_64K);
		autoconfig_product(0x03); // or 0x02 for rev 1
		autoconfig_rom_vector(0x2000);
		autoconfig_rom_vector_valid(true);
		autoconfig_link_into_memory(false);
		autoconfig_multi_device(false);

		// first device configured
		m_configured = true;
	}
	else
	{
		if (VERBOSE)
			logerror("-> installing dmac\n");

		// internal dmac registers
		m_space->install_readwrite_handler(address, address + 0xff,
			read16_delegate(FUNC(dmac_device::register_read), this),
			write16_delegate(FUNC(dmac_device::register_write), this), 0xffff);

		// install access to the rom space
		if (m_rom)
		{
			m_space->install_rom(address + 0x2000, address + 0x7fff, m_rom + 0x2000);
			m_space->install_rom(address + 0x8000, address + 0xffff, m_rom);
		}

		// stop responding to autoconfig
		m_space->unmap_readwrite(0xe80000, 0xe8007f);

		// we're done
		m_cfgout_handler(0);
	}
}
Beispiel #19
0
void wd33c9x_base_device::load_transfer_count()
{
	if (m_regs[COMMAND] & COMMAND_SBT) {
		m_transfer_count = 1;
	}
	else {
		m_transfer_count = (
			(uint32_t(m_regs[TRANSFER_COUNT_MSB]) << 16) |
			(uint32_t(m_regs[TRANSFER_COUNT])     <<  8) |
			(uint32_t(m_regs[TRANSFER_COUNT_LSB]) <<  0)
		);
		if (m_transfer_count == 0) {
			m_transfer_count = 1;
		}
	}
	LOGMASKED(LOG_COMMANDS, "%s: Transfer Count %d bytes\n", shortname(), m_transfer_count);
}
Beispiel #20
0
void
global_help(char *args)
{
    int col, len;
    struct mode *p;
    char *name, *prev;

    move(CMDLINE, col = 0);
    name = prev = NULL;
    for (p = modes; p->c_name; p++) {
        if ((name = shortname(args, p->c_name)) == NULL)
            continue;
        if (name && prev && strcmp(name, prev) == 0) {
            free(name);
            name = NULL;
            continue;
        }
        len = strlen(name);
        if (col + len > COLS)
            break;
        addstr(name);
        col += len + 1;
        if (col + 1 < COLS)
            addch(' ');
        if (prev)
            free(prev);
        prev = name;
        name = NULL;
    }
    if (col == 0 && args) {
        standout();
        if ((int)strlen(args) < COLS - 25)
            printw("help: no matches for `%s.*'", args);
        else
            printw("help: no matches");
        standend();
    }
    clrtoeol();
    if (name)
        free(name);
    if (prev)
        free(prev);
}
Beispiel #21
0
int ExportFFmpeg::Export(AudacityProject *project,
                       int channels, const wxString &fName,
                       bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, const Tags *metadata, int subformat)
{
   if (!CheckFFmpegPresence())
      return false;
   mChannels = channels;
   // subformat index may not correspond directly to fmts[] index, convert it
   mSubFormat = AdjustFormatIndex(subformat);
   if (channels > ExportFFmpegOptions::fmts[mSubFormat].maxchannels)
   {
      wxMessageBox(
         wxString::Format(
               _("Attempted to export %d channels, but maximum number of channels for selected output format is %d"),
               channels,
               ExportFFmpegOptions::fmts[mSubFormat].maxchannels),
            _("Error"));
      return false;
   }
   mName = fName;
   TrackList *tracks = project->GetTracks();
   bool ret = true;

   if (mSubFormat >= FMT_LAST) return false;

   wxString shortname(ExportFFmpegOptions::fmts[mSubFormat].shortname);
   if (mSubFormat == FMT_OTHER)
      shortname = gPrefs->Read(wxT("/FileFormats/FFmpegFormat"),wxT("matroska"));
   ret = Init(shortname.mb_str(),project, metadata, subformat);

   if (!ret) return false;

   int pcmBufferSize = 1024;
   int numWaveTracks;
   WaveTrack **waveTracks;
   tracks->GetWaveTracks(selectionOnly, &numWaveTracks, &waveTracks);
   Mixer *mixer = CreateMixer(numWaveTracks, waveTracks,
      tracks->GetTimeTrack(),
      t0, t1,
      channels, pcmBufferSize, true,
      mSampleRate, int16Sample, true, mixerSpec);
   delete[] waveTracks;

   int updateResult = eProgressSuccess;
   {
      ProgressDialog progress(wxFileName(fName).GetName(),
         selectionOnly ?
         wxString::Format(_("Exporting selected audio as %s"), ExportFFmpegOptions::fmts[mSubFormat].description) :
         wxString::Format(_("Exporting entire file as %s"), ExportFFmpegOptions::fmts[mSubFormat].description));

      while (updateResult == eProgressSuccess) {
         sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);

         if (pcmNumSamples == 0)
            break;

         short *pcmBuffer = (short *)mixer->GetBuffer();

         EncodeAudioFrame(pcmBuffer, (pcmNumSamples)*sizeof(int16_t)*mChannels);

         updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
      }
   }

   delete mixer;

   Finalize();

   return updateResult;
}
Beispiel #22
0
void wd33c9x_base_device::set_scsi_state(uint16_t state)
{
	LOGMASKED(LOG_STEP, "%s: SCSI state change: %x to %x\n", shortname(), m_scsi_state, state);
	m_scsi_state = state;
}
Beispiel #23
0
int
initmach(Machine *m, char *name)
{
	int n, fd;
	uint64_t a[MAXNUM];
	char *p, mpt[256], buf[256];

	p = strchr(name, '!');
	if(p)
		p++;
	else
		p = name;
	m->name = estrdup(p);
	m->shortname = shortname(p);
	m->remote = (strcmp(p, mysysname) != 0);
	if(m->remote == 0)
		strcpy(mpt, "");
	else{
		snprint(mpt, sizeof mpt, "/n/%s", p);
		fd = connectexportfs(name);
		if(fd < 0){
			fprint(2, "can't connect to %s: %r\n", name);
			return 0;
		}
		/* BUG? need to use amount() now? */
		if(mount(fd, -1, mpt, MREPL, "", 'M') < 0){
			fprint(2, "stats: mount %s on %s failed (%r); trying /n/sid\n", name, mpt);
			strcpy(mpt, "/n/sid");
			if(mount(fd, -1, mpt, MREPL, "", 'M') < 0){
				fprint(2, "stats: mount %s on %s failed: %r\n", name, mpt);
				return 0;
			}
		}
	}

	snprint(buf, sizeof buf, "%s/dev/swap", mpt);
	m->swapfd = open(buf, OREAD);
	if(loadbuf(m, &m->swapfd) && readswap(m, a))
		memmove(m->devswap, a, sizeof m->devswap);
	else{
		m->devswap[Maxswap] = 100;
		m->devswap[Maxmem] = 100;
	}

	snprint(buf, sizeof buf, "%s/dev/sysstat", mpt);
	m->statsfd = open(buf, OREAD);
	if(loadbuf(m, &m->statsfd)){
		for(n=0; readnums(m, nelem(m->devsysstat), a, 0); n++)
			;
		m->nproc = n;
	}else
		m->nproc = 1;
	m->lgproc = ilog10(m->nproc);

	snprint(buf, sizeof buf, "%s/net/ether0/stats", mpt);
	m->etherfd = open(buf, OREAD);
	if(loadbuf(m, &m->etherfd) && readnums(m, nelem(m->netetherstats), a, 1))
		memmove(m->netetherstats, a, sizeof m->netetherstats);

	snprint(buf, sizeof buf, "%s/net/ether0/ifstats", mpt);
	m->ifstatsfd = open(buf, OREAD);
	if(loadbuf(m, &m->ifstatsfd)){
		/* need to check that this is a wavelan interface */
		if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1))
			memmove(m->netetherifstats, a, sizeof m->netetherifstats);
	}

	snprint(buf, sizeof buf, "%s/mnt/apm/battery", mpt);
	m->batteryfd = open(buf, OREAD);
	m->bitsybatfd = -1;
	if(m->batteryfd >= 0){
		if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
			memmove(m->batterystats, a, sizeof(m->batterystats));
	}else{
		snprint(buf, sizeof buf, "%s/dev/battery", mpt);
		m->bitsybatfd = open(buf, OREAD);
		if(loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0))
			memmove(m->batterystats, a, sizeof(m->batterystats));
	}
	snprint(buf, sizeof buf, "%s/dev/cputemp", mpt);
	m->tempfd = open(buf, OREAD);
	if(loadbuf(m, &m->tempfd))
		for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++)
			 m->temp[n] = a[0];
	return 1;
}
Beispiel #24
0
int main(int argc, char **argv)
{
    if(argc != 3)
    {
	std::cout << argv[0] << " [-d] infile.til extract_to_dir" << std::endl;

	return EXIT_SUCCESS;
    }

    std::fstream fd_data(argv[1], std::ios::in | std::ios::binary);

    if(fd_data.fail())
    {
	std::cout << "error open file: " << argv[1] << std::endl;

	return EXIT_SUCCESS;
    }

    std::string prefix(argv[2]);
    std::string shortname(argv[1]);
    
    if(shortname == "-d")
    {
    }

    shortname.replace(shortname.find("."), 4, "");
    
    prefix += SEPARATOR + shortname;

    if(0 != MKDIR(prefix.c_str()))
    {
	std::cout << "error mkdir: " << prefix << std::endl;

	return EXIT_SUCCESS;
    }

    fd_data.seekg(0, std::ios_base::end);
    u32 size = fd_data.tellg();
    fd_data.seekg(0, std::ios_base::beg);

    u16 count, width, height;
    
    fd_data.read(reinterpret_cast<char *>(&count), sizeof(u16));
    SwapLE16(count);

    fd_data.read(reinterpret_cast<char *>(&width), sizeof(u16));
    SwapLE16(width);

    fd_data.read(reinterpret_cast<char *>(&height), sizeof(u16));
    SwapLE16(height);

    char *body = new char[size];

    fd_data.read(body, size);

    SDL::Init();

    for(u16 cur = 0; cur < count; ++cur)
    {
	Surface sf(&body[width * height * cur], width, height, 1, false);
	std::string dstfile(prefix);

	dstfile += SEPARATOR;

	std::ostringstream stream;
        stream << cur;

        switch(stream.str().size())
        {
    	    case 1:
    		dstfile += "00" + stream.str();
    		break;

    	    case 2:
    		dstfile += "0" + stream.str();
    		break;

    	    default:
    		dstfile += stream.str();
    		break;
        }

#ifndef WITH_IMAGE
        dstfile += ".bmp";
#else
        dstfile += ".png";
#endif
        sf.Save(dstfile.c_str());
    }

    delete [] body;

    fd_data.close();

    std::cout << "expand to: " << prefix << std::endl;

    SDL::Quit();

    return EXIT_SUCCESS;
}
Beispiel #25
0
bool ManagerApp::CheckManagerDB() {
    int version_groups = DB_MANAGER_VERSION_GROUPS;
    int version_packages = DB_MANAGER_VERSION_PACKAGES;
    int version_authorlist = DB_MANAGER_VERSION_AUTHORLIST;
    int version_packagelist = DB_MANAGER_VERSION_PACKAGELIST;
    int version_packagelist_authors = DB_MANAGER_VERSION_PACKAGELIST_AUTHORS;
    int version_packagelist_warnings = DB_MANAGER_VERSION_PACKAGELIST_WARNINGS;
    wxSQLite3StatementBuffer temp;

    m_managerdb.Open(m_appdir.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME) + wxT("manager.db"));
    if (!m_managerdb.TableExists(wxT("versions"))) {
        m_managerdb.ExecuteUpdate(wxT("create table versions(tablename char[30], version int);"));
        temp.Format("insert into versions values ('groups', %d);", version_groups);
        m_managerdb.ExecuteUpdate(temp);
        temp.Format("insert into versions values ('packages', %d);", version_packages);
        m_managerdb.ExecuteUpdate(temp);
        temp.Format("insert into versions values ('authorlist', %d);", version_authorlist);
        m_managerdb.ExecuteUpdate(temp);
        temp.Format("insert into versions values ('packagelist', %d);", version_packagelist);
        m_managerdb.ExecuteUpdate(temp);
        temp.Format("insert into versions values ('packagelist_authors', %d);", version_packagelist_authors);
        m_managerdb.ExecuteUpdate(temp);
        temp.Format("insert into versions values ('packagelist_warnings', %d);", version_packagelist_warnings);
        m_managerdb.ExecuteUpdate(temp);
    } else {
        version_groups = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'groups';"));
        version_packages = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'packages';"));
        version_authorlist = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'authorlist';"));
        version_packagelist = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'packagelist';"));
        version_packagelist_authors = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'packagelist_authors';"));
        version_packagelist_warnings = m_managerdb.ExecuteScalar(wxT("select version from versions where tablename = 'packagelist_warnings';"));
    }
    if ((version_groups > DB_MANAGER_VERSION_GROUPS) ||
        (version_packages > DB_MANAGER_VERSION_PACKAGES) ||
        (version_authorlist > DB_MANAGER_VERSION_AUTHORLIST) ||
        (version_packagelist > DB_MANAGER_VERSION_PACKAGELIST) ||
        (version_packagelist_authors > DB_MANAGER_VERSION_PACKAGELIST_AUTHORS) ||
        (version_packagelist_warnings > DB_MANAGER_VERSION_PACKAGELIST_WARNINGS)) {
        wxLogError(_("Manager database modified by a newer version of this application."));
        return false;
    }
    if (!m_managerdb.TableExists(wxT("groups"))) {
        m_managerdb.ExecuteUpdate(wxT("create table groups(name text, guid text);"));
    }
    if (!m_managerdb.TableExists(wxT("packages"))) {
        m_managerdb.ExecuteUpdate(wxT("create table packages(name text, guid text, file text, version text);"));
    }
    if (!m_managerdb.TableExists(wxT("authorlist"))) {
        m_managerdb.ExecuteUpdate(wxT("create table authorlist(name text, guid text, official int);"));
        wxFileSystem fs;

        m_managerdb.Begin();

        try {
            xmlcpp::cXmlDoc xdoc(wxString(MEMORY_PREFIX RES_XML_AUTHORS).mb_str(wxConvUTF8), NULL);
            if (xdoc.ok()) {
                xmlcpp::cXmlNode child(xdoc.getRoot().children());
                while (child.ok()) {
                    if (child.name() == "author") {
                        wxString name(child.getPropVal("name").c_str(), wxConvUTF8);
                        name.Trim();
                        name.Trim(true);
                        wxString guid(child.getPropVal("guid").c_str(), wxConvUTF8);
                        guid.Trim();
                        guid.Trim(true);
                        if (name.IsEmpty() || guid.IsEmpty()) {
                            m_managerdb.Rollback();
                            wxLogError(_("Error in author list xml."));
                            return false;
                        }
                        temp.Format("insert into authorlist values ('%q', '%q', 1);", name.mb_str(wxConvUTF8).data(), guid.mb_str(wxConvUTF8).data());
                        m_managerdb.ExecuteUpdate(temp);
                    }
                    child.go_next();
                }
            }
        } catch (std::exception& e) {
            wxLogError(wxString(e.what(), wxConvUTF8));
        }
/*
        std::auto_ptr<wxFSFile> inputfsfile(fs.OpenFile(MEMORY_PREFIX RES_XML_AUTHORS, wxFS_READ));

        wxXmlDocument doc(*inputfsfile->GetStream());

        wxXmlNode* child = doc.GetRoot()->GetChildren();
        while (child) {
            if (child->GetName() == wxT("author")) {
                wxString name = child->GetPropVal(wxT("name"), wxT(""));
                name.Trim();
                name.Trim(true);
                wxString guid = child->GetPropVal(wxT("guid"), wxT(""));
                guid.Trim();
                guid.Trim(true);
                if (name.IsEmpty() || guid.IsEmpty()) {
                    m_managerdb.Rollback();
                    wxLogError(_("Error in author list xml."));
                    return false;
                }
                temp.Format("insert into authorlist values ('%q', '%q', 1);", name.mb_str(wxConvUTF8).data(), guid.mb_str(wxConvUTF8).data());
                m_managerdb.ExecuteUpdate(temp);
            }
            child = child->GetNext();
        }
*/
        m_managerdb.Commit();
    }
    if (!m_managerdb.TableExists(wxT("packagelist"))) {
        m_managerdb.ExecuteUpdate(wxT("create table packagelist(name text, shortname text, guid text, version text, official int);"));
    }
    if (!m_managerdb.TableExists(wxT("packagelist_authors"))) {
        m_managerdb.ExecuteUpdate(wxT("create table packagelist_authors(guid text, authorguid text);"));
    }
    if (!m_managerdb.TableExists(wxT("packagelist_warnings"))) {
        m_managerdb.ExecuteUpdate(wxT("create table packagelist_warnings(guid text, type int, descrition text);"));
    }
    if (!m_managerdb.ExecuteScalar(wxT("select count(*) from packagelist;"))) {
        wxFileSystem fs;

        m_managerdb.Begin();

        try {
            xmlcpp::cXmlDoc xdoc(wxString(MEMORY_PREFIX RES_XML_PACKAGES).mb_str(wxConvUTF8), NULL);
            if (xdoc.ok()) {
                xmlcpp::cXmlNode child(xdoc.getRoot().children());
                while (child.ok()) {
                    if (child.name() == "package") {
                        wxString name(child.getPropVal("name").c_str(), wxConvUTF8);
                        name.Trim();
                        name.Trim(true);
                        wxString shortname(child.getPropVal("shortname").c_str(), wxConvUTF8);
                        shortname.Trim();
                        shortname.Trim(true);
                        wxString guid(child.getPropVal("guid").c_str(), wxConvUTF8);
                        guid.Trim();
                        guid.Trim(true);
                        wxString version(child.getPropVal("version").c_str(), wxConvUTF8);
                        version.Trim();
                        version.Trim(true);
                        if (name.IsEmpty() || guid.IsEmpty()) {
                            m_managerdb.Rollback();
                            wxLogError(_("Error in package list xml (name and/or guid missing)."));
                            return false;
                        }
                        temp.Format("insert into packagelist values ('%q', '%q', '%q', '%q', 1);", name.mb_str(wxConvUTF8).data(),
                                    shortname.mb_str(wxConvUTF8).data(), guid.mb_str(wxConvUTF8).data(), version.mb_str(wxConvUTF8).data());
                        m_managerdb.ExecuteUpdate(temp);

                        bool haveauthor = false;
                        if (child.hasProp("authorguid")) {
                            wxString authorguid(child.getPropVal("authorguid").c_str(), wxConvUTF8);
                            authorguid.Trim();
                            authorguid.Trim(true);
                            if (authorguid.IsEmpty()) {
                                m_managerdb.Rollback();
                                wxLogError(_("Error in package list xml (authorguid empty)."));
                                return false;
                            }
                            temp.Format("insert into packagelist_authors values ('%q', '%q');", guid.mb_str(wxConvUTF8).data(), authorguid.mb_str(wxConvUTF8).data());
                            m_managerdb.ExecuteUpdate(temp);
                            haveauthor  = true;
                        }

                        xmlcpp::cXmlNode subchild(child.children());
                        while(subchild.ok()) {
                            if (subchild.name() == "author") {
                                wxString authorguid(subchild.getPropVal("guid").c_str(), wxConvUTF8);
                                authorguid.Trim();
                                authorguid.Trim(true);
                                if (authorguid.IsEmpty()) {
                                    m_managerdb.Rollback();
                                    wxLogError(_("Error in package list xml (author[guid] empty)."));
                                    return false;
                                }
                                temp.Format("insert into packagelist_authors values ('%q', '%q');", guid.mb_str(wxConvUTF8).data(), authorguid.mb_str(wxConvUTF8).data());
                                m_managerdb.ExecuteUpdate(temp);
                                haveauthor  = true;
                            } else if (subchild.name() == "warning") {
                                wxString wtype(subchild.getPropVal("type").c_str(), wxConvUTF8);
                                wtype.Trim();
                                wtype.Trim(true);
                                if (wtype.IsEmpty()) {
                                    m_managerdb.Rollback();
                                    wxLogError(_("Error in package list xml (warning[type] empty)."));
                                    return false;
                                }
                                wxString desc(subchild.content().c_str(), wxConvUTF8);
                                desc.Trim();
                                desc.Trim(true);
                                temp.Format("insert into packagelist_warnings values ('%q', '%q', '%q');", guid.mb_str(wxConvUTF8).data(), wtype.mb_str(wxConvUTF8).data(), desc.mb_str(wxConvUTF8).data());
                                m_managerdb.ExecuteUpdate(temp);
                            }
                            subchild.go_next();
                        }
                        if (!haveauthor) {
                            m_managerdb.Rollback();
                            wxLogError(_("Error in package list xml (author missing)."));
                            return false;
                        }
                    }
                    child.go_next();
                }
            } else {
                wxLogError(_("Failed to open package list xml."));
                for (std::vector<xmlcpp::cXmlStructuredError>::const_iterator it = xdoc.getStructuredErrors().begin(); it != xdoc.getStructuredErrors().end(); ++it)
                    wxLogError(wxString(it->message.c_str(), wxConvUTF8));
            }
        } catch (std::exception& e) {
            wxLogError(wxString(e.what(), wxConvUTF8));
        }

/*
        std::auto_ptr<wxFSFile> inputfsfile(fs.OpenFile(MEMORY_PREFIX RES_XML_PACKAGES, wxFS_READ));

        wxXmlDocument doc(*inputfsfile->GetStream());

        wxXmlNode* child = doc.GetRoot()->GetChildren();
        while (child) {
            if (child->GetName() == wxT("package")) {
                wxString name = child->GetPropVal(wxT("name"), wxT(""));
                name.Trim();
                name.Trim(true);
                wxString shortname = child->GetPropVal(wxT("shortname"), wxT(""));
                shortname.Trim();
                shortname.Trim(true);
                wxString guid = child->GetPropVal(wxT("guid"), wxT(""));
                guid.Trim();
                guid.Trim(true);
                wxString version = child->GetPropVal(wxT("version"), wxT("0"));
                version.Trim();
                version.Trim(true);
                if (name.IsEmpty() || guid.IsEmpty()) {
                    m_managerdb.Rollback();
                    wxLogError(_("Error in package list xml (name and/or guid missing)."));
                    return false;
                }
                temp.Format("insert into packagelist values ('%q', '%q', '%q', '%q', 1);", name.mb_str(wxConvUTF8).data(),
                            shortname.mb_str(wxConvUTF8).data(), guid.mb_str(wxConvUTF8).data(), version.mb_str(wxConvUTF8).data());
                m_managerdb.ExecuteUpdate(temp);

                bool haveauthor = false;
                if (child->HasProp(wxT("authorguid"))) {
                    wxString authorguid = child->GetPropVal(wxT("authorguid"), wxT(""));
                    authorguid.Trim();
                    authorguid.Trim(true);
                    if (authorguid.IsEmpty()) {
                        m_managerdb.Rollback();
                        wxLogError(_("Error in package list xml (authorguid empty)."));
                        return false;
                    }
                    temp.Format("insert into packagelist_authors values ('%q', '%q');", guid.mb_str(wxConvUTF8).data(), authorguid.mb_str(wxConvUTF8).data());
                    m_managerdb.ExecuteUpdate(temp);
                    haveauthor  = true;
                }

                wxXmlNode* subchild = child->GetChildren();
                while(subchild) {
                    if (subchild->GetName() == wxT("author")) {
                        wxString authorguid = subchild->GetPropVal(wxT("guid"), wxT(""));
                        authorguid.Trim();
                        authorguid.Trim(true);
                        if (authorguid.IsEmpty()) {
                            m_managerdb.Rollback();
                            wxLogError(_("Error in package list xml (author[guid] empty)."));
                            return false;
                        }
                        temp.Format("insert into packagelist_authors values ('%q', '%q');", guid.mb_str(wxConvUTF8).data(), authorguid.mb_str(wxConvUTF8).data());
                        m_managerdb.ExecuteUpdate(temp);
                        haveauthor  = true;
                    } else if (subchild->GetName() == wxT("warning")) {
                        wxString wtype = subchild->GetPropVal(wxT("type"), wxT(""));
                        wtype.Trim();
                        wtype.Trim(true);
                        if (wtype.IsEmpty()) {
                            m_managerdb.Rollback();
                            wxLogError(_("Error in package list xml (warning[type] empty)."));
                            return false;
                        }
                        wxString desc = subchild->GetNodeContent();
                        desc.Trim();
                        desc.Trim(true);
                        temp.Format("insert into packagelist_warnings values ('%q', '%q', '%q');", guid.mb_str(wxConvUTF8).data(), wtype.mb_str(wxConvUTF8).data(), desc.mb_str(wxConvUTF8).data());
                        m_managerdb.ExecuteUpdate(temp);
                    }
                    subchild = subchild->GetNext();
                }
                if (!haveauthor) {
                    m_managerdb.Rollback();
                    wxLogError(_("Error in package list xml (author missing)."));
                    return false;
                }
            }
            child = child->GetNext();
        }
*/
        m_managerdb.Commit();
    }
    return true;
}
Beispiel #26
0
bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, int frameSize)
{
   AVPacket	pkt;
   int		nBytesToWrite = 0;
   uint8_t *	pRawSamples = NULL;
   int		nAudioFrameSizeOut = mEncAudioCodecCtx->frame_size * mEncAudioCodecCtx->channels * sizeof(int16_t);
   if (mEncAudioCodecCtx->frame_size == 1) nAudioFrameSizeOut = mEncAudioEncodedBufSiz;
   int      ret;

   nBytesToWrite = frameSize;
   pRawSamples  = (uint8_t*)pFrame;
#if FFMPEG_STABLE
   FFmpegLibsInst->av_fifo_realloc(&mEncAudioFifo, FFmpegLibsInst->av_fifo_size(&mEncAudioFifo) + frameSize);
#else
   FFmpegLibsInst->av_fifo_realloc2(mEncAudioFifo, FFmpegLibsInst->av_fifo_size(mEncAudioFifo) + frameSize);
#endif
   // Put the raw audio samples into the FIFO.
#if FFMPEG_STABLE
   ret = FFmpegLibsInst->av_fifo_generic_write(&mEncAudioFifo, pRawSamples, nBytesToWrite,NULL);
#else
   ret = FFmpegLibsInst->av_fifo_generic_write(mEncAudioFifo, pRawSamples, nBytesToWrite,NULL);
#endif
   wxASSERT(ret == nBytesToWrite);

   // Read raw audio samples out of the FIFO in nAudioFrameSizeOut byte-sized groups to encode.
#if FFMPEG_STABLE
   while ((ret = FFmpegLibsInst->av_fifo_size(&mEncAudioFifo)) >= nAudioFrameSizeOut)
   {
      ret = FFmpegLibsInst->av_fifo_read(&mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut);
#else
   while ((ret = FFmpegLibsInst->av_fifo_size(mEncAudioFifo)) >= nAudioFrameSizeOut)
   {
      ret = FFmpegLibsInst->av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut, NULL);
#endif
      FFmpegLibsInst->av_init_packet(&pkt);

      pkt.size = FFmpegLibsInst->avcodec_encode_audio(mEncAudioCodecCtx, 
         mEncAudioEncodedBuf, mEncAudioEncodedBufSiz,		// out
         (int16_t*)mEncAudioFifoOutBuf);				// in
      if (mEncAudioCodecCtx->frame_size == 1) { wxASSERT(pkt.size == mEncAudioEncodedBufSiz); }
      if (pkt.size < 0)
      {
         wxLogMessage(wxT("FFmpeg : ERROR - Can't encode audio frame."));
         return false;
      }

      // Rescale from the codec time_base to the AVStream time_base.
      if (mEncAudioCodecCtx->coded_frame && mEncAudioCodecCtx->coded_frame->pts != int64_t(AV_NOPTS_VALUE))
         pkt.pts = FFmpegLibsInst->av_rescale_q(mEncAudioCodecCtx->coded_frame->pts, mEncAudioCodecCtx->time_base, mEncAudioStream->time_base);
      //wxLogMessage(wxT("FFmpeg : (%d) Writing audio frame with PTS: %lld."), mEncAudioCodecCtx->frame_number, pkt.pts);

      pkt.stream_index = mEncAudioStream->index;
      pkt.data = mEncAudioEncodedBuf;
      pkt.flags |= PKT_FLAG_KEY;

      // Write the encoded audio frame to the output file.
      if ((ret = FFmpegLibsInst->av_interleaved_write_frame(mEncFormatCtx, &pkt)) != 0)
      {
         wxLogMessage(wxT("FFmpeg : ERROR - Failed to write audio frame to file."));
         return false;
      }
   }
   return true;
}


int ExportFFmpeg::Export(AudacityProject *project,
                       int channels, wxString fName,
                       bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, Tags *metadata, int subformat)
{
   if (!CheckFFmpegPresence())
      return false;
   mChannels = channels;
   // subformat index may not correspond directly to fmts[] index, convert it
   mSubFormat = AdjustFormatIndex(subformat);
   if (channels > ExportFFmpegOptions::fmts[mSubFormat].maxchannels)
   {
      wxLogMessage(wxT("Attempted to export %d channels, but max. channels = %d"),channels,ExportFFmpegOptions::fmts[mSubFormat].maxchannels);
      wxMessageBox(wxString::Format(_("Attempted to export %d channels, but max. channels for selected output format is %d"),channels,ExportFFmpegOptions::fmts[mSubFormat].maxchannels),_("Error"));
      return false;
   }
   mName = fName;
   TrackList *tracks = project->GetTracks();
   bool ret = true;

   if (mSubFormat >= FMT_LAST) return false;
   
   wxString shortname(ExportFFmpegOptions::fmts[mSubFormat].shortname);
   if (mSubFormat == FMT_OTHER)
      shortname = gPrefs->Read(wxT("/FileFormats/FFmpegFormat"),wxT("matroska"));
   ret = Init(shortname.mb_str(),project, metadata);

   if (!ret) return false;

   int pcmBufferSize = 1024;
   int numWaveTracks;
   WaveTrack **waveTracks;
   tracks->GetWaveTracks(selectionOnly, &numWaveTracks, &waveTracks);
   Mixer *mixer = new Mixer(numWaveTracks, waveTracks,
      tracks->GetTimeTrack(),
      t0, t1,
      channels, pcmBufferSize, true,
      mSampleRate, int16Sample, true, mixerSpec);
   delete [] waveTracks;

   ProgressDialog *progress = new ProgressDialog(wxFileName(fName).GetName(),
      selectionOnly ?
      wxString::Format(_("Exporting selected audio as %s"), ExportFFmpegOptions::fmts[mSubFormat].description) :
   wxString::Format(_("Exporting entire file as %s"), ExportFFmpegOptions::fmts[mSubFormat].description));

   int updateResult = eProgressSuccess;

   while(updateResult == eProgressSuccess) {
      sampleCount pcmNumSamples = mixer->Process(pcmBufferSize);

      if (pcmNumSamples == 0)
         break;

      short *pcmBuffer = (short *)mixer->GetBuffer();

      EncodeAudioFrame(pcmBuffer,(pcmNumSamples)*sizeof(int16_t)*mChannels);

      updateResult = progress->Update(mixer->MixGetCurrentTime()-t0, t1-t0);
   }

   delete progress;

   delete mixer;

   Finalize();

   return updateResult;
}

void AddStringTagUTF8(char field[], int size, wxString value)
{
      memset(field,0,size);
      memcpy(field,value.ToUTF8(),(int)strlen(value.ToUTF8()) > size -1 ? size -1 : strlen(value.ToUTF8()));
}
Beispiel #27
0
/* wrapper Audio::Play */
void AGG::PlayMusic(const MUS::mus_t mus, bool loop)
{
    static MUS::mus_t old = MUS::UNKNOWN;
    const Settings & conf = Settings::Get();

    if(!conf.Music() || MUS::UNUSED == mus || MUS::UNKNOWN == mus || (old == mus && Music::isPlaying())) return;

    old = mus;
    
    if(conf.MusicExt())
    {
	const std::string musname(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + MUS::GetString(mus));
#ifdef WITH_MIXER
	std::string shortname(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + MUS::GetString(mus, true));
	const char* filename = NULL;

	if(FilePresent(musname))   filename = musname.c_str();
	else
	if(FilePresent(shortname)) filename = shortname.c_str();
	else
	{
	    String::Replace(shortname, ".ogg", ".mp3");
	    if(FilePresent(shortname)) filename = shortname.c_str();
	    else
		DEBUG(DBG_ENGINE , DBG_WARN, "AGG::PlayMusic: error read file: " << musname << ", skipping...");
	}

	if(filename) Music::Play(filename, loop);
#else
	if(FilePresent(musname) && conf.PlayMusCommand().size())
	{
	    const std::string run = conf.PlayMusCommand() + " " + musname;
	    Music::Play(run.c_str(), loop);
	}
#endif
	DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: " << MUS::GetString(mus));
    }
    else
#ifdef WITH_AUDIOCD
    if(conf.MusicCD() && Cdrom::isValid())
    {
	Cdrom::Play(mus, loop);
	DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: cd track " << static_cast<int>(mus));
    }
    else
#endif
    if(conf.MusicMIDI())
    {
	XMI::xmi_t xmi = XMI::FromMUS(mus);
	if(XMI::UNKNOWN != xmi)
	{
#ifdef WITH_MIXER
	    const std::vector<u8> & v = AGG::Cache::Get().GetMID(xmi);
	    if(v.size()) Music::Play(&v[0], v.size(), loop);
#else
	    if(conf.PlayMusCommand().size())
	    {
		const std::string file = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + XMI::GetString(xmi);
		if(FilePresent(file))
		{
		    const std::string run = conf.PlayMusCommand() + " " + file;
		    Music::Play(run.c_str(), loop);
		}
		else
		    StoreMemToFile(AGG::Cache::Get().GetMID(xmi), file);
	    }
#endif
	}
	DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: " << XMI::GetString(xmi));
    }
}
Beispiel #28
0
void wd33c9x_base_device::start_command()
{
	const uint8_t cc = m_regs[COMMAND] & COMMAND_CC;

	// Command In Progress
	//  The CIP flag being set only means that the WD33C9x is
	//  *interpreting* the contents of the Command Register.
	//  It shouldn't actually be set.
	//m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_CIP;
	if (cc > COMMAND_CC_DISCONNECT && cc != COMMAND_CC_SET_IDI) {
		m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_BSY;
	}

	switch (cc) {
	case COMMAND_CC_RESET:
		LOGMASKED(LOG_COMMANDS, "%s: Reset Command\n", shortname());
		scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
		scsi_bus->ctrl_wait(scsi_refid, S_SEL|S_BSY|S_RST, S_ALL);
		m_regs[OWN_ID] = m_command_length;
		memset(&m_regs[CONTROL], 0, SOURCE_ID - CONTROL);
		m_regs[COMMAND] = 0;
		m_regs[AUXILIARY_STATUS] &= ~AUXILIARY_STATUS_DBR;
		m_mode = MODE_D;
		data_fifo_reset();
		irq_fifo_reset();
		update_irq();
		set_scsi_state(FINISHED);
		irq_fifo_push((m_regs[OWN_ID] & OWN_ID_EAF) ? SCSI_STATUS_RESET_EAF : SCSI_STATUS_RESET);
		scsi_id = (m_regs[OWN_ID] & OWN_ID_SCSI_ID);
		break;

	case COMMAND_CC_ABORT:
		LOGMASKED(LOG_COMMANDS, "%s: Abort Command\n", shortname());
		set_scsi_state(FINISHED);
		// FIXME
		irq_fifo_push((m_regs[OWN_ID] & OWN_ID_EAF) ? SCSI_STATUS_RESET_EAF : SCSI_STATUS_RESET);
		break;

	case COMMAND_CC_ASSERT_ATN:
		LOGMASKED(LOG_COMMANDS, "%s: Assert ATN Command\n", shortname());
		if (m_mode != MODE_I) {
			fatalerror("%s: ASSERT_ATN command only valid in the Initiator state.", shortname());
		}
		scsi_bus->ctrl_w(scsi_refid, S_ATN, S_ATN);
		return;

	case COMMAND_CC_NEGATE_ACK:
		LOGMASKED(LOG_COMMANDS, "%s: Negate ACK Command\n", shortname());
		// FIXME - This is causing problems, so ignore for now.
		//if (m_mode != MODE_I) {
		//  fatalerror("NEGATE_ACK command only valid in the Initiator state.");
		//}
		scsi_bus->ctrl_w(scsi_refid, 0, S_ACK);
		return;

	case COMMAND_CC_DISCONNECT:
		LOGMASKED(LOG_COMMANDS, "%s: Disconnect Command\n", shortname());
		scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
		scsi_bus->ctrl_wait(scsi_refid, S_SEL|S_BSY|S_RST, S_ALL);
		m_mode = MODE_D;
		set_scsi_state(IDLE);
		m_regs[AUXILIARY_STATUS] &= ~(AUXILIARY_STATUS_CIP | AUXILIARY_STATUS_BSY);
		break;

	case COMMAND_CC_SELECT:
	case COMMAND_CC_SELECT_ATN:
		LOGMASKED(LOG_COMMANDS, "%s: %s Command\n", shortname(), select_strings[cc - COMMAND_CC_SELECT_ATN]);
		if (m_mode != MODE_D) {
			fatalerror("Select commands only valid in the Disconnected state.");
		}
		set_scsi_state((ARB_WAIT_BUS_FREE << SUB_SHIFT) | DISC_SEL_ARBITRATION);
		break;

	case COMMAND_CC_SELECT_TRANSFER:
	case COMMAND_CC_SELECT_ATN_TRANSFER:
		LOGMASKED(LOG_COMMANDS, "%s: %s Command\n", shortname(), select_strings[cc - COMMAND_CC_SELECT_ATN]);
		if (m_mode == MODE_D) {
			set_scsi_state((ARB_WAIT_BUS_FREE << SUB_SHIFT) | DISC_SEL_ARBITRATION);
			m_regs[COMMAND_PHASE] = COMMAND_PHASE_ZERO;
		}
		else if (m_mode == MODE_I) {
			set_scsi_state(INIT_XFR);
		}
		else {
			fatalerror("%s: Select-and-Transfer commands only valid in the Disconnected and Initiator states.", shortname());
		}
		set_command_length(cc);
		load_transfer_count();
		break;

	case COMMAND_CC_TRANSFER_INFO:
		LOGMASKED(LOG_COMMANDS, "%s: Transfer Info Command\n", shortname());
		if (m_mode != MODE_I) {
			fatalerror("%s: TRANSFER_INFO command only valid in the Initiator state.", shortname());
		}
		m_regs[AUXILIARY_STATUS] &= ~AUXILIARY_STATUS_DBR;
		set_scsi_state(INIT_XFR);
		set_command_length(COMMAND_CC_TRANSFER_INFO);
		load_transfer_count();
		m_xfr_phase = (scsi_bus->ctrl_r() & S_PHASE_MASK);
		step(false);
		return;

	default:
		fatalerror("%s: Unimplemented command: 0x%02x", shortname(), cc);
		break;
	}

	delay(1);
}
Beispiel #29
0
ExportFFmpeg::ExportFFmpeg()
:  ExportPlugin()
{
   mEncFormatDesc = NULL;      // describes our output file to libavformat
   mEncAudioStream = NULL;     // the output audio stream (may remain NULL)
   #define MAX_AUDIO_PACKET_SIZE (128 * 1024)
   mEncAudioFifoOutBufSiz = 0;

   mSampleRate = 0;
   mSupportsUTF8 = true;

   PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg destructor
   int avfver = FFmpegLibsInst->ValidLibsLoaded() ? avformat_version() : 0;
   int newfmt;
   // Adds export types from the export type list
   for (newfmt = 0; newfmt < FMT_LAST; newfmt++)
   {
      wxString shortname(ExportFFmpegOptions::fmts[newfmt].shortname);
      //Don't hide export types when there's no av-libs, and don't hide FMT_OTHER
      if (newfmt < FMT_OTHER && FFmpegLibsInst->ValidLibsLoaded())
      {
         // Format/Codec support is compiled in?
         AVOutputFormat *avoformat = av_guess_format(shortname.mb_str(), NULL, NULL);
         AVCodec *avcodec = avcodec_find_encoder(ExportFFmpegOptions::fmts[newfmt].codecid);
         if (avoformat == NULL || avcodec == NULL)
         {
            ExportFFmpegOptions::fmts[newfmt].compiledIn = false;
            continue;
         }
      }
      int fmtindex = AddFormat() - 1;
      SetFormat(ExportFFmpegOptions::fmts[newfmt].name,fmtindex);
      AddExtension(ExportFFmpegOptions::fmts[newfmt].extension,fmtindex);
      // For some types add other extensions
      switch(newfmt)
      {
      case FMT_M4A:
         AddExtension(wxString(wxT("3gp")),fmtindex);
         AddExtension(wxString(wxT("m4r")),fmtindex);
         AddExtension(wxString(wxT("mp4")),fmtindex);
         break;
      case FMT_WMA2:
         AddExtension(wxString(wxT("asf")),fmtindex);
         AddExtension(wxString(wxT("wmv")),fmtindex);
         break;
      default:
         break;
      }

      SetMaxChannels(ExportFFmpegOptions::fmts[newfmt].maxchannels,fmtindex);
      SetDescription(ExportFFmpegOptions::fmts[newfmt].description,fmtindex);

      int canmeta = ExportFFmpegOptions::fmts[newfmt].canmetadata;
      if (canmeta && (canmeta == AV_VERSION_INT(-1,-1,-1) || canmeta <= avfver))
      {
         SetCanMetaData(true,fmtindex);
      }
      else
      {
         SetCanMetaData(false,fmtindex);
      }
   }
}
Beispiel #30
0
void wd33c9x_base_device::step(bool timeout)
{
	if (++m_step_count > 1) {
		return;
	}

	const uint8_t cc = (m_regs[COMMAND] & COMMAND_CC);
	const bool sat = (cc == COMMAND_CC_SELECT_TRANSFER || cc == COMMAND_CC_SELECT_ATN_TRANSFER);

	uint32_t cycles = 0;
	do {
		const uint32_t ctrl = scsi_bus->ctrl_r();
		const uint32_t data = scsi_bus->data_r();

		m_step_count = 1;

		LOGMASKED(LOG_STEP,
			"%s: step - PHASE:%s BSY:%x SEL:%x REQ:%x ACK:%x ATN:%x RST:%x DATA:%x (%d.%d) %s\n",
			shortname(),
			phase_strings[ctrl & S_PHASE_MASK],
			(ctrl & S_BSY) ? 1 : 0,
			(ctrl & S_SEL) ? 1 : 0,
			(ctrl & S_REQ) ? 1 : 0,
			(ctrl & S_ACK) ? 1 : 0,
			(ctrl & S_ATN) ? 1 : 0,
			(ctrl & S_RST) ? 1 : 0,
			data,
			m_scsi_state & STATE_MASK, m_scsi_state >> SUB_SHIFT,
			(timeout) ? "timeout" : "change"
		);

		if (m_mode == MODE_I) {
			if (ctrl & S_BSY) {
				if (ctrl & S_REQ) {
					uint8_t xfr_phase = (ctrl & S_PHASE_MASK);
					switch (m_scsi_state) {
					case DISC_SEL_ARBITRATION:
						m_xfr_phase = xfr_phase;
						break;

					case INIT_XFR_WAIT_REQ:
						break;

					default:
						if (m_xfr_phase != xfr_phase) {
							fatalerror("%s: Unexpected phase change during state.\n", shortname());
						}
						break;
					}
				}
			}
			else {
				LOGMASKED(LOG_STATE, "%s: Target disconnected\n", shortname());
				if (sat) {
					switch (m_regs[COMMAND_PHASE]) {
					case COMMAND_PHASE_DISCONNECT_MESSAGE:
						set_scsi_state(FINISHED);
						m_regs[COMMAND_PHASE] = COMMAND_PHASE_DISCONNECTED;
						break;

					case COMMAND_PHASE_COMMAND_COMPLETE:
						if (m_regs[CONTROL] & CONTROL_EDI) {
							set_scsi_state(FINISHED);
							irq_fifo_push(SCSI_STATUS_SELECT_TRANSFER_SUCCESS);
						}
						break;

					default:
						fatalerror("%s: Unhandled command phase during Select-and-Transfer disconnect.\n", shortname());
						break;
					}
				}
				else {
					set_scsi_state(FINISHED);
					irq_fifo_push(SCSI_STATUS_DISCONNECT);
				}
				m_mode = MODE_D;
				scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
				scsi_bus->ctrl_wait(scsi_refid, S_SEL|S_BSY|S_RST, S_ALL);
				continue;
			}
		}

		switch (m_scsi_state & SUB_MASK ? m_scsi_state & SUB_MASK : m_scsi_state & STATE_MASK) {
		case IDLE:
			break;

		case FINISHED:
			set_scsi_state(IDLE);
			m_regs[AUXILIARY_STATUS] &= ~(AUXILIARY_STATUS_CIP | AUXILIARY_STATUS_BSY);
			update_irq();
			break;

		case ARB_WAIT_BUS_FREE << SUB_SHIFT:
			if (timeout) {
				if (!(ctrl & (S_BSY | S_SEL))) {
					set_scsi_state_sub(ARB_CHECK_FREE);
				}
				cycles = 1;
			}
			break;

		case ARB_CHECK_FREE << SUB_SHIFT:
			if (timeout) {
				uint8_t next_state;
				if (ctrl & (S_BSY | S_SEL)) {
					next_state  = ARB_WAIT_BUS_FREE;
					cycles = 1;
				}
				else {
					scsi_bus->data_w(scsi_refid, 1 << scsi_id);
					scsi_bus->ctrl_w(scsi_refid, S_BSY, S_BSY);
					next_state = ARB_EXAMINE_BUS;
					cycles = 1;
				}
				set_scsi_state_sub(next_state);
			}
			break;

		case ARB_EXAMINE_BUS << SUB_SHIFT:
			if (timeout) {
				if (ctrl & S_SEL) {
					scsi_bus->ctrl_w(scsi_refid, 0, S_BSY);
					scsi_bus->data_w(scsi_refid, 0);
					set_scsi_state_sub(ARB_WAIT_BUS_FREE);
				}
				else {
					int win;
					for (win = 7; win >=0 && !(data & (1 << win)); win--) {};
					if (win == scsi_id) {
						scsi_bus->ctrl_w(scsi_refid, S_SEL, S_SEL);
						set_scsi_state_sub(ARB_ASSERT_SEL);
					}
					else {
						scsi_bus->data_w(scsi_refid, 0);
						scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
					}
				}
				cycles = 1;
			}
			break;

		case ARB_ASSERT_SEL << SUB_SHIFT:
			if (timeout) {
				scsi_bus->data_w(scsi_refid, (1 << scsi_id) | (1 << (m_regs[DESTINATION_ID] & DESTINATION_ID_DI)));
				set_scsi_state_sub(ARB_SET_DEST);
				cycles = 1;
			}
			break;

		case ARB_SET_DEST << SUB_SHIFT:
			if (timeout) {
				scsi_bus->ctrl_w(scsi_refid, (cc == COMMAND_CC_SELECT_ATN || cc == COMMAND_CC_SELECT_ATN_TRANSFER) ? S_ATN : 0, S_ATN | S_BSY);
				set_scsi_state_sub(ARB_RELEASE_BUSY);
				cycles = 1;
			}
			break;

		case ARB_RELEASE_BUSY << SUB_SHIFT:
			if (timeout) {
				if (ctrl & S_BSY) {
					set_scsi_state_sub(ARB_DESKEW_WAIT);
					if (cc == COMMAND_CC_RESELECT) {
						scsi_bus->ctrl_w(scsi_refid, S_BSY, S_BSY);
					}
					cycles = 1;
				}
				else {
					set_scsi_state_sub(ARB_TIMEOUT_BUSY);
					cycles = 1;
				}
			}
			break;

		case ARB_DESKEW_WAIT << SUB_SHIFT:
			if (timeout) {
				scsi_bus->data_w(scsi_refid, 0);
				scsi_bus->ctrl_w(scsi_refid, 0, S_SEL);
				m_mode = (cc == COMMAND_CC_RESELECT) ? MODE_T : MODE_I;
				set_scsi_state_sub(0);
				++m_step_count;
			}
			break;

		case ARB_TIMEOUT_BUSY << SUB_SHIFT:
			if (timeout) {
				scsi_bus->data_w(scsi_refid, 0);
				set_scsi_state_sub(ARB_TIMEOUT_ABORT);
				cycles = 1000;
			}
			else if (ctrl & S_BSY) {
				set_scsi_state_sub(ARB_DESKEW_WAIT);
				if (cc == COMMAND_CC_RESELECT) {
					scsi_bus->ctrl_w(scsi_refid, S_BSY, S_BSY);
				}
				cycles = 1;
			}
			break;

		case ARB_TIMEOUT_ABORT << SUB_SHIFT:
			if (timeout) {
				if (ctrl & S_BSY) {
					set_scsi_state_sub(ARB_DESKEW_WAIT);
					if (cc == COMMAND_CC_RESELECT) {
						scsi_bus->ctrl_w(scsi_refid, S_BSY, S_BSY);
					}
					cycles = 1;
				}
				else {
					scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
					scsi_bus->ctrl_wait(scsi_refid, S_SEL|S_BSY|S_RST, S_ALL);
					m_regs[AUXILIARY_STATUS] &= ~(AUXILIARY_STATUS_CIP | AUXILIARY_STATUS_BSY);
					m_mode = MODE_D;
					set_scsi_state(IDLE);
					irq_fifo_push(SCSI_STATUS_SELECTION_TIMEOUT);
					update_irq();
				}
			}
			break;

		case SEND_WAIT_SETTLE << SUB_SHIFT:
			if (timeout) {
				set_scsi_state_sub(SEND_WAIT_REQ_0);
				++m_step_count;
			}
			break;

		case SEND_WAIT_REQ_0 << SUB_SHIFT:
			if (!(ctrl & S_REQ)) {
				set_scsi_state_sub(0);
				scsi_bus->data_w(scsi_refid, 0);
				scsi_bus->ctrl_w(scsi_refid, 0, S_ACK);
				if (sat) {
					switch (m_xfr_phase) {
					case S_PHASE_COMMAND:
						++m_regs[COMMAND_PHASE];
						break;
					}
				}
				++m_step_count;
			}
			break;

		case RECV_WAIT_REQ_1 << SUB_SHIFT:
			if (ctrl & S_REQ) {
				set_scsi_state_sub(RECV_WAIT_SETTLE);
				cycles = 1;
			}
			break;

		case RECV_WAIT_SETTLE << SUB_SHIFT:
			if (timeout) {
				if (sat) {
					switch (m_xfr_phase) {
					case S_PHASE_DATA_IN:
						data_fifo_push(data);
						if ((m_regs[CONTROL] & CONTROL_DM) != CONTROL_DM_POLLED) {
							set_drq();
						}
						else {
							decrement_transfer_count();
							m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
						}
						break;

					case S_PHASE_STATUS:
						m_regs[TARGET_LUN] = data;
						m_regs[COMMAND_PHASE] = COMMAND_PHASE_STATUS_RECEIVED;
						break;

					case S_PHASE_MSG_IN:
						data_fifo_push(data);
						break;

					default:
						fatalerror("%s: Unexpected phase in RECV_WAIT_SETTLE.\n", shortname());
						break;
					}
				}
				else {
					data_fifo_push(data);
					if (m_xfr_phase == S_PHASE_DATA_IN && (m_regs[CONTROL] & CONTROL_DM) != CONTROL_DM_POLLED) {
						set_drq();
					}
					else {
						decrement_transfer_count();
						m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
					}
				}
				set_scsi_state_sub(RECV_WAIT_REQ_0);
				scsi_bus->ctrl_w(scsi_refid, S_ACK, S_ACK);
				++m_step_count;
			}
			break;

		case RECV_WAIT_REQ_0 << SUB_SHIFT:
			if (!(ctrl & S_REQ)) {
				set_scsi_state_sub(0);
				++m_step_count;
			}
			break;

		case DISC_SEL_ARBITRATION:
 			scsi_bus->ctrl_wait(scsi_refid, S_REQ, S_REQ);
			if (cc == COMMAND_CC_SELECT || cc == COMMAND_CC_SELECT_ATN) {
				set_scsi_state(FINISHED);
				irq_fifo_push(SCSI_STATUS_SELECT_SUCCESS);
				if (ctrl & S_REQ) {
					irq_fifo_push(SCSI_STATUS_REQ | m_xfr_phase);
				}
			}
			else {
				set_scsi_state(INIT_XFR);
				m_regs[COMMAND_PHASE] = COMMAND_PHASE_SELECTED;
			}
			++m_step_count;
			break;

		case INIT_XFR:
			if (ctrl & S_REQ) {
				switch (m_xfr_phase) {
				case S_PHASE_DATA_OUT:
					if ((m_regs[CONTROL] & CONTROL_DM) != CONTROL_DM_POLLED) {
						while (!data_fifo_full() && m_transfer_count > 0) {
							set_drq();
						}
					}
					if (!data_fifo_empty()) {
						set_scsi_state(INIT_XFR_WAIT_REQ);
						cycles = send_byte();
					}
					else if ((m_regs[CONTROL] & CONTROL_DM) == CONTROL_DM_POLLED) {
						m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
					}
					break;

				case S_PHASE_COMMAND:
					if (!data_fifo_empty()) {
						uint32_t mask;
						if (sat) {
							mask = 0;
						}
						else {
							m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
							mask = (m_transfer_count == 0 && m_data_fifo_size == 1) ? S_ATN : 0;
						}
						set_scsi_state(INIT_XFR_WAIT_REQ);
						cycles = send_byte(0, mask);
					}
					else if (!sat) {
						m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
					}
					break;

				case S_PHASE_MSG_OUT:
					if (sat) {
						data_fifo_push(get_msg_out());
					}
					if (!data_fifo_empty()) {
						uint32_t mask;
						if (sat) {
							mask = S_ATN;
						}
						else {
							m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
							mask = (m_transfer_count == 0 && m_data_fifo_size == 1) ? S_ATN : 0;
						}
						set_scsi_state(INIT_XFR_WAIT_REQ);
						cycles = send_byte(0, mask);
					}
					else if (!sat) {
						m_regs[AUXILIARY_STATUS] |= AUXILIARY_STATUS_DBR;
					}
					break;

				case S_PHASE_DATA_IN:
				case S_PHASE_STATUS:
				case S_PHASE_MSG_IN:
					if (!data_fifo_full()) {
						// if it's the last message byte, ACK remains asserted, terminate with function_complete()
						//state = (m_xfr_phase == S_PHASE_MSG_IN && (!dma_command || tcounter == 1)) ? INIT_XFR_RECV_BYTE_NACK : INIT_XFR_RECV_BYTE_ACK;
						scsi_bus->ctrl_wait(scsi_refid, S_REQ, S_REQ);
						set_scsi_state((RECV_WAIT_REQ_1 << SUB_SHIFT) | INIT_XFR_RECV_BYTE_ACK);
						if (ctrl & S_REQ) {
							++m_step_count;
						}
					}
					break;

				default:
					fatalerror("%s: Invalid phase during INIT_XFR.\n", shortname());
					break;
				}
			}
			break;

		case INIT_XFR_WAIT_REQ:
			if (ctrl & S_REQ) {
				uint16_t next_state = m_scsi_state;

				const uint8_t xfr_phase = (ctrl & S_PHASE_MASK);

				switch ((m_xfr_phase << 3) | xfr_phase) {
				case ((S_PHASE_MSG_OUT << 3) | S_PHASE_MSG_OUT):
				case ((S_PHASE_COMMAND << 3) | S_PHASE_COMMAND):
				case ((S_PHASE_MSG_IN  << 3) | S_PHASE_MSG_IN):
					next_state = INIT_XFR;
					break;

				case ((S_PHASE_DATA_IN  << 3) | S_PHASE_DATA_IN):
				case ((S_PHASE_DATA_OUT << 3) | S_PHASE_DATA_OUT):
					if (sat || cc == COMMAND_CC_TRANSFER_INFO) {
						if (m_transfer_count > 0 || (m_xfr_phase == S_PHASE_DATA_OUT && !data_fifo_empty())) {
							next_state = INIT_XFR;
						}
						else {
							next_state = FINISHED;
							uint8_t scsi_status;
							if (sat) {
								m_regs[COMMAND_PHASE] = COMMAND_PHASE_TRANSFER_COUNT;
								scsi_status = SCSI_STATUS_UNEXPECTED_PHASE;
							}
							else {
								scsi_status = SCSI_STATUS_TRANSFER_SUCCESS;
							}
							irq_fifo_push(scsi_status | m_xfr_phase);
						}
					}
					else {
						fatalerror("%s: Unhandled command in data phase.\n", shortname());
						next_state = FINISHED;
					}
					break;

				case ((S_PHASE_MSG_OUT  << 3) | S_PHASE_COMMAND):
				case ((S_PHASE_COMMAND  << 3) | S_PHASE_DATA_OUT):
				case ((S_PHASE_COMMAND  << 3) | S_PHASE_DATA_IN):
				case ((S_PHASE_COMMAND  << 3) | S_PHASE_STATUS):
				case ((S_PHASE_COMMAND  << 3) | S_PHASE_MSG_IN):
				case ((S_PHASE_DATA_OUT << 3) | S_PHASE_STATUS):
				case ((S_PHASE_DATA_IN  << 3) | S_PHASE_STATUS):
				case ((S_PHASE_STATUS   << 3) | S_PHASE_MSG_IN):
					if (!(m_xfr_phase & 1) && !data_fifo_empty()) {
						fatalerror("%s: Data FIFO is not empty on phase transition.\n", shortname());
					}

					if (sat) {
						switch (xfr_phase) {
						case S_PHASE_MSG_OUT:
							next_state = INIT_XFR;
							break;

						case S_PHASE_COMMAND:
							next_state = INIT_XFR;
							m_regs[COMMAND_PHASE] = COMMAND_PHASE_CP_BYTES_0;
							LOGMASKED(LOG_COMMANDS, "%s: Sending Command:", shortname());
							for (uint8_t i = 0; i < m_command_length; ++i) {
								const uint8_t command_byte = m_regs[CDB_1 + i];
								LOGMASKED(LOG_COMMANDS, " %02x", command_byte);
								data_fifo_push(command_byte);
							}
							LOGMASKED(LOG_COMMANDS, " (%d)\n", m_transfer_count);
							break;

						case S_PHASE_DATA_OUT:
						case S_PHASE_DATA_IN:
							next_state = INIT_XFR;
							break;

						case S_PHASE_STATUS:
							next_state = INIT_XFR;
							m_regs[COMMAND_PHASE] = COMMAND_PHASE_RECEIVE_STATUS;
							break;

						case S_PHASE_MSG_IN:
							next_state = INIT_XFR;
							break;

						default:
							fatalerror("%s: Unhandled phase in Select-w/Atn-and-Transfer.\n", shortname());
							next_state = FINISHED;
							break;
						}
					}
					else if (cc == COMMAND_CC_TRANSFER_INFO) {
						next_state = FINISHED;
						irq_fifo_push(SCSI_STATUS_TRANSFER_SUCCESS | xfr_phase);
					}
					else {
						fatalerror("%s: Unhandled command in data phase.\n", shortname());
						next_state = FINISHED;
					}
					break;

				default:
					fatalerror("%s: Unhandled phase transition in INIT_XFR_WAIT_REQ.\n", shortname());
					next_state = FINISHED;
					break;
				}

				if (next_state != m_scsi_state) {
					set_scsi_state(next_state);
					++m_step_count;
					m_xfr_phase = xfr_phase;
				}
			}
			break;

		case INIT_XFR_RECV_BYTE_ACK:
			if (sat && m_xfr_phase == S_PHASE_MSG_IN) {
				const uint8_t msg = data_fifo_pop();
				if (m_regs[COMMAND_PHASE] <= COMMAND_PHASE_CP_BYTES_C) {
					switch (msg) {
					case SM_SAVE_DATA_PTR:
						set_scsi_state(FINISHED);
						irq_fifo_push(SCSI_STATUS_SAVE_DATA_POINTERS);
						m_regs[COMMAND_PHASE] = COMMAND_PHASE_SAVE_DATA_POINTER;
						break;

					case SM_DISCONNECT:
						m_regs[COMMAND_PHASE] = COMMAND_PHASE_DISCONNECT_MESSAGE;
						break;

					default:
						fatalerror("%s: Unhandled MSG_IN.\n", shortname());
						break;
					}
				}
				else if (m_regs[COMMAND_PHASE] < COMMAND_PHASE_COMMAND_COMPLETE) {
					switch (msg) {
					case SM_COMMAND_COMPLETE:
						set_scsi_state(FINISHED);
						irq_fifo_push(SCSI_STATUS_SELECT_TRANSFER_SUCCESS);
						m_regs[COMMAND_PHASE] = COMMAND_PHASE_COMMAND_COMPLETE;
						break;
					default:
						fatalerror("%s: Unhandled MSG_IN.\n", shortname());
						break;
					}
				}
			}
			else {
				set_scsi_state(INIT_XFR_WAIT_REQ);
			}
			scsi_bus->ctrl_w(scsi_refid, 0, S_ACK);
			++m_step_count;
			break;

		default:
			fatalerror("%s: Unhandled state in step.\n", shortname());
			break;
		}

		timeout = false;

	} while (--m_step_count);

	if (cycles) {
		delay(cycles);
	}
}