int32_t uaenet_open (struct uaenetdata *sd, struct netdriverdata *tc, struct s2devstruct *user, uaenet_gotfunc *gotfunc, uaenet_getfunc *getfunc, int32_t promiscuous) { char *s; s = ua (tc->name); sd->fp = pcap_open_live (s, 65536, promiscuous, 100, sd->errbuf); xfree (s); if (sd->fp == NULL) { TCHAR *ss = au (sd->errbuf); write_log ("'%s' failed to open: %s\n", tc->name, ss); xfree (ss); return 0; } sd->tc = tc; sd->user = user; sd->mtu = tc->mtu; sd->readbuffer = xmalloc (uint8_t, sd->mtu); sd->writebuffer = xmalloc (uint8_t, sd->mtu); sd->gotfunc = gotfunc; sd->getfunc = getfunc; uae_sem_init (&sd->change_sem, 0, 1); uae_sem_init (&sd->sync_semr, 0, 0); uae_start_thread ("uaenet_r", uaenet_trap_threadr, sd, &sd->tidr); uae_sem_wait (&sd->sync_semr); uae_sem_init (&sd->sync_semw, 0, 0); uae_start_thread ("uaenet_w", uaenet_trap_threadw, sd, &sd->tidw); uae_sem_wait (&sd->sync_semw); write_log ("uaenet initialized\n"); return 1; }
void consolehook_ret (uaecptr condev, uaecptr oldbeginio) { beginio = oldbeginio; write_log (L"console.device at %08X\n", condev); uae_start_thread (L"consolereader", console_thread, NULL, NULL); }
void consolehook_ret(TrapContext *ctx, uaecptr condev, uaecptr oldbeginio) { beginio = oldbeginio; write_log (_T("console.device at %08X\n"), condev); uae_start_thread (_T("consolereader"), console_thread, NULL, NULL); }
/* play CD audio */ static int ioctl_command_play (int unitnum, int startlsn, int endlsn, int scan, play_status_callback statusfunc, play_subchannel_callback subfunc) { struct dev_info_ioctl *ciw = unitisopen (unitnum); if (!ciw) return 0; ciw->cdda_play_finished = 0; ciw->cdda_subfunc = subfunc; ciw->cdda_statusfunc = statusfunc; ciw->cdda_scan = scan > 0 ? 10 : (scan < 0 ? 10 : 0); ciw->cdda_delay = setstate (ciw, -1); ciw->cdda_delay_frames = setstate (ciw, -2); setstate (ciw, AUDIO_STATUS_NOT_SUPPORTED); if (!open_createfile (ciw, 0)) { setstate (ciw, AUDIO_STATUS_PLAY_ERROR); return 0; } if (!isaudiotrack (&ciw->di.toc, startlsn)) { setstate (ciw, AUDIO_STATUS_PLAY_ERROR); return 0; } if (!ciw->cdda_play) { uae_start_thread (_T("ioctl_cdda_play"), cdda_play, ciw, NULL); } ciw->cdda_start = startlsn; ciw->cdda_end = endlsn; ciw->cd_last_pos = ciw->cdda_start; ciw->cdda_play++; return 1; }
cda_audio::cda_audio(int num_sectors, int sectorsize) { write_log("cda_audio::cda_audio(num_sectors=%d)\n", num_sectors); #if 0 mStopThread = 0; mBufferDone[0] = 1; mBufferDone[1] = 1; uae_start_thread("cdda", audio_thread, this, &mThread); #endif active = false; playing = false; volume[0] = volume[1] = 0; bufsize = num_sectors * sectorsize; this->sectorsize = sectorsize; for (int i = 0; i < 2; i++) { buffer_ids[i] = 0; buffers[i] = xcalloc (uae_u8, num_sectors * ((bufsize + 4095) & ~4095)); } this->num_sectors = num_sectors; active = true; playing = true; }
/* * Set up extended trap context and call handler function */ static void trap_HandleExtendedTrap (TrapHandler handler_func, int has_retval) { struct TrapContext *context = xcalloc (TrapContext, 1); if (context) { uae_sem_init (&context->switch_to_trap_sem, 0, 0); uae_sem_init (&context->switch_to_emu_sem, 0, 0); context->trap_handler = handler_func; context->trap_has_retval = has_retval; context->saved_regs = regs; /* Copy of regs to be restored when trap is done */ /* Start thread to handle new trap context. */ uae_start_thread ("Trap", trap_thread, (void *)context, &context->thread); /* Switch to trap context to begin execution of * trap handler function. */ uae_sem_post (&context->switch_to_trap_sem); /* Wait for trap context to switch back to us. * * It'll do this when the trap handler is done - or when * the handler wants to call 68k code. */ uae_sem_wait (&context->switch_to_emu_sem); } }
static int32_t start_thread (struct devstruct *dev) { init_comm_pipe (&dev->requests, 100, 1); uae_sem_init (&dev->sync_sem, 0, 0); uae_start_thread (_T("uaeserial"), dev_thread, dev, NULL); uae_sem_wait (&dev->sync_sem); return dev->thread_running; }
int uaenet_open (void *vsd, struct netdriverdata *tc, void *user, uaenet_gotfunc *gotfunc, uaenet_getfunc *getfunc, int promiscuous, const uae_u8 *mac) { struct uaenetdatawin32 *sd = (struct uaenetdatawin32*)vsd; char *s; s = ua (tc->name); if (mac) memcpy(tc->mac, mac, 6); if (memcmp(tc->mac, tc->originalmac, 6)) { promiscuous = 1; } sd->fp = ppcap_open(s, 65536, (promiscuous ? PCAP_OPENFLAG_PROMISCUOUS : 0) | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 100, NULL, sd->errbuf); xfree (s); if (sd->fp == NULL) { TCHAR *ss = au (sd->errbuf); write_log (_T("'%s' failed to open: %s\n"), tc->name, ss); xfree (ss); return 0; } sd->tc = tc; sd->user = user; sd->evttw = CreateEvent (NULL, FALSE, FALSE, NULL); if (!sd->evttw) goto end; sd->mtu = tc->mtu; sd->readbuffer = xmalloc (uae_u8, sd->mtu); sd->writebuffer = xmalloc (uae_u8, sd->mtu); sd->gotfunc = gotfunc; sd->getfunc = getfunc; uae_sem_init (&sd->change_sem, 0, 1); uae_sem_init (&sd->sync_semr, 0, 0); uae_start_thread (_T("uaenet_win32r"), uaenet_trap_threadr, sd, &sd->tidr); uae_sem_wait (&sd->sync_semr); uae_sem_init (&sd->sync_semw, 0, 0); uae_start_thread (_T("uaenet_win32w"), uaenet_trap_threadw, sd, &sd->tidw); uae_sem_wait (&sd->sync_semw); write_log (_T("uaenet_win32 initialized\n")); return 1; end: uaenet_close (sd); return 0; }
/* We need a thread for this, since communication between finish_sound_buffer * and the callback works through semaphores. In theory, this is unnecessary, * since SDL uses a sound thread internally, and the callback runs in its * context. But we don't want to depend on SDL's internals too much. */ static void init_sound_thread(void) { write_log("init_sound_thread\n"); uae_thread_id tid; init_comm_pipe (&to_sound_pipe, 20, 1); uae_sem_init (&data_available_sem, 0, 0); uae_sem_init (&callback_done_sem, 0, 0); uae_sem_init (&sound_init_sem, 0, 0); uae_start_thread ("Sound", sound_thread, NULL, &tid); }
static int start_thread (struct s2devstruct *dev) { if (dev->thread_running) return 1; init_comm_pipe (&dev->requests, 100, 1); uae_sem_init (&dev->sync_sem, 0, 0); uae_start_thread (SANA2NAME, dev_thread, dev, NULL); uae_sem_wait (&dev->sync_sem); return dev->thread_running; }
static int start_thread (struct scsidevdata *sdd) { #ifdef UAE_SCSIDEV_THREADS if (sdd->thread_running) return 1; init_comm_pipe (&sdd->requests, 10, 1); uae_sem_init (&sdd->sync_sem, 0, 0); uae_start_thread (scsidev_thread, sdd, &sdd->tid); uae_sem_wait (&sdd->sync_sem); return sdd->thread_running; #else return 1; #endif }
bool uae_slirp_start (void) { #ifdef WITH_QEMU_SLIRP if (impl == QEMU_IMPLEMENTATION) { UAE_LOG_STUB(""); return true; } #endif #ifdef WITH_BUILTIN_SLIRP if (impl == BUILTIN_IMPLEMENTATION) { uae_slirp_end (); uae_start_thread(_T("slirp-receive"), slirp_receive_func, NULL, &slirp_tid); return true; } #endif return false; }
int graphics_setup(void) { #ifdef PICASSO96 picasso_InitResolutions(); InitPicasso96(); #endif VCHI_INSTANCE_T vchi_instance; VCHI_CONNECTION_T *vchi_connection; TV_DISPLAY_STATE_T tvstate; if(vchi_initialise(&vchi_instance) == 0) { if(vchi_connect(NULL, 0, vchi_instance) == 0) { vc_vchi_tv_init(vchi_instance, &vchi_connection, 1); if(vc_tv_get_display_state(&tvstate) == 0) { HDMI_PROPERTY_PARAM_T property; property.property = HDMI_PROPERTY_PIXEL_CLOCK_TYPE; vc_tv_hdmi_get_property(&property); float frame_rate = property.param1 == HDMI_PIXEL_CLOCK_TYPE_NTSC ? tvstate.display.hdmi.frame_rate * (1000.0f/1001.0f) : tvstate.display.hdmi.frame_rate; host_hz = (int)frame_rate; time_per_host_frame = time_for_host_hz_frames / host_hz; } vc_vchi_tv_stop(); vchi_disconnect(vchi_instance); } } if(display_pipe == 0) { display_pipe = xmalloc (smp_comm_pipe, 1); init_comm_pipe(display_pipe, 20, 1); } if(display_sem == 0) { uae_sem_init (&display_sem, 0, 0); } if(display_tid == 0 && display_pipe != 0 && display_sem != 0) { uae_start_thread(_T("render"), display_thread, NULL, &display_tid); } write_comm_pipe_u32(display_pipe, DISPLAY_SIGNAL_SETUP, 1); return 1; }
static int command_play (int unitnum, int startlsn, int endlsn, int scan, play_status_callback statusfunc, play_subchannel_callback subfunc) { struct cdunit *cdu = unitisopen (unitnum); if (!cdu) return 0; cdu->cd_last_pos = startlsn; cdu->cdda_start = startlsn; cdu->cdda_end = endlsn; cdu->cdda_subfunc = subfunc; cdu->cdda_statusfunc = statusfunc; cdu->cdda_scan = scan > 0 ? 10 : (scan < 0 ? 10 : 0); cdu->cdda_delay = setstate (cdu, -1); cdu->cdda_delay_frames = setstate (cdu, -2); setstate (cdu, AUDIO_STATUS_NOT_SUPPORTED); if (!isaudiotrack (&cdu->di.toc, startlsn)) { setstate (cdu, AUDIO_STATUS_PLAY_ERROR); return 0; } if (!cdu->cdda_play) uae_start_thread (_T("cdimage_cdda_play"), cdda_play_func, cdu, NULL); cdu->cdda_play++; return 1; }
void uae_ppc_cpu_reboot(void) { TRACE(_T("uae_ppc_cpu_reboot\n")); initialize(); if (!ppc_thread_running) { write_log(_T("Starting PPC thread.\n")); ppc_thread_running = true; if (using_qemu()) { uae_ppc_cpu_reset(); //qemu_uae_ppc_start(); impl.set_state(PPC_CPU_STATE_RUNNING); //set_and_wait_for_state(PPC_CPU_STATE_RUNNING, 0); } else { uae_start_thread(NULL, ppc_thread, NULL, NULL); } } else if (using_qemu()) { write_log(_T("PPC: Thread already running, resetting\n")); uae_ppc_cpu_reset(); set_and_wait_for_state(PPC_CPU_STATE_RUNNING, 1); } }
int uae_start_thread_fast (void *(*f)(void *), void *arg, uae_thread_id *thread) { // FIXME: what is the supposed difference between uae_start_thread and // uae_start_thread_fast? return uae_start_thread(NULL, f, arg, thread); }
int uae_start_thread_fast (void *(*f)(void *), void *arg, uae_thread_id *tid) { bug("[JUAE:PX] %s(%lx, %lx, %lx)\n", __PRETTY_FUNCTION__, f, arg, tid); uae_start_thread(NULL, f, arg, tid); }
uae_u32 uaenative_call_function (TrapContext *context, int flags) { if (!currprefs.native_code) { return UNI_ERROR_NOT_ENABLED; } struct uni uni; uni.function = m68k_areg (regs, 0); if (flags & UNI_FLAG_COMPAT) { uni.library = 0; #ifdef AHI uni.uaevar_compat = uaenative_get_uaevar(); #else uni.uaevar_compat = NULL; #endif } else if (flags & UNI_FLAG_NAMED_FUNCTION) { uni.library = m68k_dreg (regs, 0); } else { uni.library = 0; } struct library_data *library_data; if (uni.library) { // library handle given, function is pointer to function name const char *function = (const char *) get_real_address (uni.function); library_data = get_library_data_from_handle (uni.library); if (library_data == NULL) { write_log (_T("uni: get_function - invalid library (%d)\n"), uni.library); return UNI_ERROR_INVALID_LIBRARY; } uni.native_function = dl_symbol (library_data->dl_handle, function); if (uni.native_function == NULL) { write_log (_T("uni: get_function - function (%s) not found ") _T("in library %d (%p)\n"), function, uni.library, library_data->dl_handle); return UNI_ERROR_FUNCTION_NOT_FOUND; } } else { // library handle not given, function argument is function handle int index = uni.function - (uae_u32) 0x80000000; if (index >= 0 && index <= g_max_handle) { uni.native_function = g_handles[index].function; library_data = g_handles[index].library; } else { uni.native_function = NULL; } if (uni.native_function == NULL) { // printf ("UNI_ERROR_INVALID_FUNCTION\n"); return UNI_ERROR_INVALID_FUNCTION; } } if (context == NULL) { // we have no context and cannot call into m68k space flags &= ~UNI_FLAG_ASYNCHRONOUS; } uni.d1 = m68k_dreg (regs, 1); uni.d2 = m68k_dreg (regs, 2); uni.d3 = m68k_dreg (regs, 3); uni.d4 = m68k_dreg (regs, 4); uni.d5 = m68k_dreg (regs, 5); uni.d6 = m68k_dreg (regs, 6); uni.d7 = m68k_dreg (regs, 7); uni.a1 = m68k_areg (regs, 1); uni.a2 = m68k_areg (regs, 2); uni.a3 = m68k_areg (regs, 3); uni.a4 = m68k_areg (regs, 4); uni.a5 = m68k_areg (regs, 5); uni.a7 = m68k_areg (regs, 7); uni.flags = flags; uni.error = 0; if (flags & UNI_FLAG_ASYNCHRONOUS) { uaecptr sysbase = get_long (4); uni.task = get_long (sysbase + 276); // ThisTask // make sure signal bit is cleared m68k_dreg (regs, 0) = 0; m68k_dreg (regs, 1) = 1 << SIGBIT; CallLib (context, sysbase, -0x132); // SetSignal // start thread if necessary if (!library_data->thread_id) { uae_sem_init (&library_data->full_count, 0, 0); // we don't have a queue as such, the thread only processes // one item at a time with a "queue size" of 1 uae_sem_init (&library_data->empty_count, 0, 1); uae_start_thread (_T("uaenative"), uaenative_thread, library_data, &library_data->thread_id); } // signal async thread to process new function call uae_sem_wait(&library_data->empty_count); library_data->uni = &uni; uae_sem_post(&library_data->full_count); // wait for signal m68k_dreg (regs, 0) = 1 << SIGBIT; CallLib (context, sysbase, -0x13e); // Wait write_log (_T("uni: -- Got async result --\n")); } else { // synchronous mode, just call the function here and now do_call_function(&uni); } return uni.result; }