int S9xOpenGLDisplayDriver::init () { initialized = false; if (!create_context ()) { return -1; } if (!opengl_defaults ()) { return -1; } buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); clear_buffers (); padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset); padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset); GFX.Screen = (uint16 *) padded_buffer[0]; GFX.Pitch = image_width * image_bpp; context->swap_interval (config->sync_to_vblank); initialized = true; return 0; }
void solver_type:: ensure_buffer_size ( solve_1d_functor_type const & calc_1d_functor , size_type x_size , size_type y_size ) // The 1d functors know how big a buffer they need. { // Make sure the buffers are big enough to handle the solve. // And shrink them or release them if they are too big. if ( not_early_exit( ) ) { size_type const now_buf_size = buf_a_.size( ); size_type const min_buf_size = calc_1d_functor.get_min_buf_count( x_size, y_size); if ( (min_buf_size > now_buf_size) || (min_buf_size < (now_buf_size / 2)) ) { if ( min_buf_size == 0 ) { clear_buffers( ); } else { buf_a_.resize( min_buf_size); buf_iter_a_ = buf_a_.begin( ); buf_b_.resize( min_buf_size); buf_iter_b_ = buf_b_.begin( ); } } d_assert( buf_a_.size( ) >= min_buf_size); d_assert( buf_b_.size( ) >= min_buf_size); } }
void traite_pleinecran(GEM_WINDOW *gwnd) { GEM_WINDOW *wprog ; VXIMAGE *vimage ; MFDB out ; float x_level, y_level, level ; int xy[8] ; int cp ; if ( gwnd == NULL ) return ; vimage = (VXIMAGE *) gwnd->Extension ; mouse_busy() ; x_level = (float)(Xmax-2)/(float)vimage->raster.fd_w ; y_level = (float)(Ymax-2)/(float)vimage->raster.fd_h ; if (x_level > y_level) level = y_level ; else level = x_level ; wprog = DisplayStdProg(msg[MSG_CALCREDUC], "", "", CLOSER ) ; out.fd_addr = NULL ; out.fd_w = (int) ( 0.5 + (float)vimage->raster.fd_w * level ) ; out.fd_h = (int) ( 0.5 + (float)vimage->raster.fd_h * level ) ; /* if (raster_pczoom(&vimage->raster, &out, level, level, wprog))*/ if ( RasterZoom( &vimage->raster, &out, wprog ) ) { GWDestroyWindow( wprog ) ; form_error(8) ; mouse_restore() ; return ; } GWDestroyWindow( wprog ) ; mouse_restore() ; cp = config.color_protect ; config.color_protect = 0 ; set_imgpalette( vimage ) ; cls_gemscreen() ; clear_buffers( MU_KEYBD | MU_BUTTON ) ; xy[0] = 0 ; xy[1] = 0 ; xy[2] = out.fd_w-1 ; xy[3] = out.fd_h-1 ; xy[4] = (Xmax-xy[2])/2 ; xy[5] = (Ymax-xy[3])/2 ; xy[6] = xy[4]+xy[2] ; xy[7] = xy[5]+xy[3] ; v_hide_c(handle) ; wind_update(BEG_UPDATE) ; vro_cpyfm(handle, S_ONLY, xy, &out, &screen) ; wait_for( MU_KEYBD | MU_BUTTON ) ; wind_update(END_UPDATE) ; free(out.fd_addr) ; restore_gemscreen(GemApp.Menu) ; v_show_c(handle, 1) ; config.color_protect = cp ; set_imgpalette( vimage ) ; }
void Audio::resume_audio() { if (sound_enabled) { clear_buffers(); SDL_PauseAudioDevice(dev,0); } }
int32_t uart_uninitialize (void) { RCC->APB2ENR &= ~(1 << 14); GPIOA->CRH &= ~(0xFF << 4); GPIOA->CRH |= (0x44 << 4); NVIC_DisableIRQ(USART1_IRQn); /* Disable USART interrupt */ clear_buffers(); return 1; }
int32_t uart_reset (void) { NVIC_DisableIRQ(USART1_IRQn); /* Enable USART interrupt */ clear_buffers(); tx_in_progress = 0; NVIC_EnableIRQ (USART1_IRQn); /* Enable USART interrupt */ return 1; }
void Reverb::configure_buffers() { clear_buffers(); //clear if necesary for (int i=0;i<MAX_COMBS;i++) { Comb &c=comb[i]; c.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate); int len=lrint(comb_tunings[i]*params.mix_rate)+c.extra_spread_frames; if (len<5) len=5; //may this happen? c.buffer = memnew_arr(float,len); c.pos=0; for (int j=0;j<len;j++) c.buffer[j]=0; c.size=len; } for (int i=0;i<MAX_ALLPASS;i++) { AllPass &a=allpass[i]; a.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate); int len=lrint(allpass_tunings[i]*params.mix_rate)+a.extra_spread_frames; if (len<5) len=5; //may this happen? a.buffer = memnew_arr(float,len); a.pos=0; for (int j=0;j<len;j++) a.buffer[j]=0; a.size=len; } echo_buffer_size=(int)(((float)MAX_ECHO_MS/1000.0)*params.mix_rate+1.0); echo_buffer = memnew_arr(float,echo_buffer_size); for (int i=0;i<echo_buffer_size;i++) { echo_buffer[i]=0; } echo_buffer_pos=0; }
void create_buffers() { clear_buffers(); usize sz = calc_buffer_size(); OSStatus sta; for (core::vector<AudioQueueBufferRef>::iterator each = buffers.begin(); each != buffers.end(); ++each) { if ((sta = AudioQueueAllocateBuffer(d_owner->queue, sz, &*each))) { trace_fmt("failed to allocate audio buffer, %.4s", (char*)&sta); } } }
int S9xOpenGLDisplayDriver::init (void) { int padding; opengl_defaults (); /* Create two system buffers to avoid DMA contention */ buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); // TODO MIKEL the "+ 32" is to prevent overflow from drawing to the right, fix the overflow buffer[2] = malloc (image_padded_size + 32); // buffers for second (anaglyphed) screen buffer[3] = malloc (scaled_padded_size + 32); combined_buffer = malloc(scaled_padded_size); clear_buffers (); padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padded_buffer[2] = (void *) (((uint8 *) buffer[2]) + padding); padding = (scaled_padded_size - scaled_size) / 2; padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); padded_buffer[3] = (void *) (((uint8 *) buffer[3]) + padding); padded_combined_buffer = (void *) (((uint8 *) padded_combined_buffer) + padding); GFX.Screen = (uint16 *) padded_buffer[0]; GFX.Screen2 = (uint16 *) padded_buffer[2]; GFX.Pitch = image_width * image_bpp; filtering = -1; this->swap_control (config->sync_to_vblank); return 0; }
int S9xOpenGLDisplayDriver::init (void) { int padding; initialized = 0; if (!init_glx ()) { return -1; } if (!opengl_defaults ()) { return -1; } /* Create two system buffers to avoid DMA contention */ buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); clear_buffers (); padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padding = (scaled_padded_size - scaled_size) / 2; padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); GFX.Screen = (uint16 *) padded_buffer[0]; GFX.Pitch = image_width * image_bpp; filtering = -1; swap_control (config->sync_to_vblank); initialized = 1; return 0; }
int main( void ) { int j; //----------Set up descriptors tDMA_descriptor DMA_PPI0[2]; DMA_PPI0[0].NDPL = ((unsigned long int)&DMA_PPI0[1]) & 0xffff; DMA_PPI0[0].NDPH = (((unsigned long int)&DMA_PPI0[1]) & 0xffff0000)>>16; DMA_PPI0[0].SAL = ((unsigned long int)buffer16) & 0xffff; DMA_PPI0[0].SAH = (((unsigned long int)buffer16) & 0xffff0000)>>16; DMA_PPI0[0].DMACFG = DMA0_CONF|0x1; DMA_PPI0[1].NDPL = ((unsigned long int)&DMA_PPI0[1]) & 0xffff; DMA_PPI0[1].NDPH = (((unsigned long int)&DMA_PPI0[1]) & 0xffff0000)>>16; DMA_PPI0[1].SAL = ((unsigned long int)&term) & 0xffff; DMA_PPI0[1].SAH = (((unsigned long int)&term) & 0xffff0000)>>16; DMA_PPI0[1].DMACFG = (DMA0_CONF|0x1)&0x00FF; //----------------------------- printf("Entered CoreB\n"); // printf("B32_addr: 0x%x, B16_addr: 0x%x\n",&buffer32,&buffer16); buffer_full = false; InitInterrupts_Rx(); clear_buffers(); InitPPI0(&DMA_PPI0[0]); ssync(); EnablePPI0(); ssync(); while(*pDMA1_0_IRQ_STATUS & DMA_RUN); DisablePPI0(); ssync(); return 0; }
int perfmon_buffer_ctl(void *data) { struct perfmon_struct *pdata; int err; pdata = kmalloc(sizeof(struct perfmon_struct), GFP_USER); err = __copy_from_user(pdata, data, sizeof(struct perfmon_struct)); switch(pdata->header.subcmd) { case PMC_SUBCMD_BUFFER_ALLOC: alloc_perf_buffer(0); break; case PMC_SUBCMD_BUFFER_FREE: free_perf_buffer(); break; case PMC_SUBCMD_BUFFER_CLEAR: clear_buffers(); break; default: return(-1); } return(0); }
void solver_type:: calc_next_wave_with_damping ( method_type method , bool is_parallel_method , rate_type damping , rate_type x_rate , rate_type y_rate , sheet_type const & src_sheet , sheet_type & trg_sheet ) { // Damping cannot be one of the special values. Those are only used to make the // mixing algorithms work. d_assert( damping != finite_difference::get_no_init_damping_set_value< rate_type >( )); d_assert( damping != finite_difference::get_no_init_damping_sum_value< rate_type >( )); // We solve forward-diff with 2-d functions instead the 1-d functors for all the others. if ( method == e_forward_diff ) { clear_buffers( ); // forward-diff doesn't need buffers -- free their alloc'd memory if ( is_parallel_method ) { // We don't use a functor for 2d forward diff. Instead we have two functions: // one for serial and one for parallel. // We have to pass in all the state since we don't have a functor to wrap it up for us. calc_next_2d_forward_diff_parallel ( output_params_.ref_early_exit( ) , damping, x_rate, y_rate , src_sheet.get_range_yx( ) , trg_sheet.get_range_yx( ) ); } else { // The serial (not parallel) 2d forward-diff function. calc_next_2d_forward_diff_serial ( output_params_.ref_early_exit( ) , damping, x_rate, y_rate , src_sheet.get_range_yx( ) , trg_sheet.get_range_yx( ) ); } } else /* central or backward diff */ { // We use the 1d functors. The damping params tell them how we're using them. d_assert( (method == e_backward_diff) || (method == e_central_diff)); // Get the appropriate 1d functor. solve_1d_functor_type const & calc_1d_functor = get_1d_functor( method, is_parallel_method); ensure_buffer_size( calc_1d_functor, src_sheet.get_x_count( ), src_sheet.get_y_count( )); // This is a 2-pass algorithm that uses different damping values for each pass. rate_type const damping_1st_pass = damping; rate_type const damping_2nd_pass = finite_difference::get_no_init_damping_sum_value< rate_type >( ); // Two pass algorithms: // The 1st pass calculates values from src_sheet and writes them to trg_sheet. // The 2nd pass calculates other values from the original src_sheet and sums them into trg_sheet. // Improve? Since the first pass does slightly more work, perhaps we should do the narrow // dimension first? Although it probably doesn't matter at all. // We could just copy if (damping==1) and (x_rate==0) and (y_rate==0). calc_1d_functor( damping_1st_pass, x_rate, src_sheet.get_range_yx( ), trg_sheet.get_range_yx( )); if ( not_early_exit( ) ) { // 2nd-pass damping says use +=. calc_1d_functor( damping_2nd_pass, y_rate, src_sheet.get_range_xy( ), trg_sheet.get_range_xy( )); } } }
static int ds_rsd_open(void* data, wav_header_t *w) { ds_t* ds = data; if (DirectSoundCreate(NULL, &ds->ds, NULL) != DS_OK) return -1; if (IDirectSound_SetCooperativeLevel(ds->ds, GetDesktopWindow(), DSSCL_NORMAL) != DS_OK) return -1; int bits = 16; ds->fmt = w->rsd_format; ds->conv = converter_fmt_to_s16ne(w->rsd_format); ds->rings = 16; ds->latency = DEFAULT_CHUNK_SIZE * 2; WAVEFORMATEX wfx = { .wFormatTag = WAVE_FORMAT_PCM, .nChannels = w->numChannels, .nSamplesPerSec = w->sampleRate, .wBitsPerSample = bits, .nBlockAlign = w->numChannels * bits / 8, .nAvgBytesPerSec = w->sampleRate * w->numChannels * bits / 8, }; DSBUFFERDESC bufdesc = { .dwSize = sizeof(DSBUFFERDESC), .dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS, .dwBufferBytes = ds->rings * ds->latency, .lpwfxFormat = &wfx, }; if (IDirectSound_CreateSoundBuffer(ds->ds, &bufdesc, &ds->dsb, 0) != DS_OK) return -1; IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); clear_buffers(ds); IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING); return 0; } static size_t ds_rsd_write(void *data, const void* inbuf, size_t size) { ds_t *ds = data; size_t osize = size; uint8_t convbuf[2 * size]; const uint8_t *buffer_ptr = inbuf; if (ds->conv != RSD_NULL) { if (rsnd_format_to_bytes(ds->fmt) == 1) osize = 2 * size; else if (rsnd_format_to_bytes(ds->fmt) == 4) osize = size / 2; memcpy(convbuf, inbuf, size); audio_converter(convbuf, ds->fmt, ds->conv, size); buffer_ptr = convbuf; } // With this approach we are prone to underruns which would "ring", // but the RSound API does not really encourage letting stuff underrun anyways. ds->writering = (ds->writering + 1) % ds->rings; for (;;) { DWORD pos; IDirectSoundBuffer_GetCurrentPosition(ds->dsb, &pos, 0); unsigned activering = pos / ds->latency; if (activering != ds->writering) break; Sleep(1); } void *output1, *output2; DWORD size1, size2; HRESULT res; if ((res = IDirectSoundBuffer_Lock(ds->dsb, ds->writering * ds->latency, osize, &output1, &size1, &output2, &size2, 0)) != DS_OK) { if (res != DSERR_BUFFERLOST) return 0; if (IDirectSoundBuffer_Restore(ds->dsb) != DS_OK) return 0; if (IDirectSoundBuffer_Lock(ds->dsb, ds->writering * ds->latency, osize, &output1, &size1, &output2, &size2, 0) != DS_OK) return 0; } memcpy(output1, buffer_ptr, size1); memcpy(output2, buffer_ptr + size1, size2); IDirectSoundBuffer_Unlock(ds->dsb, output1, size1, output2, size2); return size; } static int ds_rsd_latency(void* data) { ds_t *ds = data; DWORD pos; IDirectSoundBuffer_GetCurrentPosition(ds->dsb, &pos, 0); DWORD next_writepos = ((ds->writering + 1) % ds->rings) * ds->latency; if (next_writepos <= pos) next_writepos += ds->rings * ds->latency; int delta = next_writepos - pos; if (rsnd_format_to_bytes(ds->fmt) == 1) delta /= 2; else if (rsnd_format_to_bytes(ds->fmt) == 4) delta *= 2; return delta; }
Reverb::~Reverb() { memdelete_arr(input_buffer); clear_buffers(); }
/* * Main command processor. * Accept and execute commands until a quit command. */ void commands(void) { int c = 0; int action; char *cbuf; int newaction; int save_search_type; char *extra; char tbuf[2]; PARG parg; IFILE old_ifile; IFILE new_ifile; char *tagfile; search_type = SRCH_FORW; wscroll = (sc_height + 1) / 2; newaction = A_NOACTION; for (;;) { mca = 0; cmd_accept(); number = 0; curropt = NULL; /* * See if any signals need processing. */ if (sigs) { psignals(); if (quitting) quit(QUIT_SAVED_STATUS); } /* * Display prompt and accept a character. */ cmd_reset(); prompt(); if (sigs) continue; if (newaction == A_NOACTION) c = getcc(); again: if (sigs) continue; if (newaction != A_NOACTION) { action = newaction; newaction = A_NOACTION; } else { /* * If we are in a multicharacter command, call mca_char. * Otherwise we call fcmd_decode to determine the * action to be performed. */ if (mca) switch (mca_char(c)) { case MCA_MORE: /* * Need another character. */ c = getcc(); goto again; case MCA_DONE: /* * Command has been handled by mca_char. * Start clean with a prompt. */ continue; case NO_MCA: /* * Not a multi-char command * (at least, not anymore). */ break; } /* * Decode the command character and decide what to do. */ if (mca) { /* * We're in a multichar command. * Add the character to the command buffer * and display it on the screen. * If the user backspaces past the start * of the line, abort the command. */ if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0) continue; cbuf = get_cmdbuf(); } else { /* * Don't use cmd_char if we're starting fresh * at the beginning of a command, because we * don't want to echo the command until we know * it is a multichar command. We also don't * want erase_char/kill_char to be treated * as line editing characters. */ tbuf[0] = (char)c; tbuf[1] = '\0'; cbuf = tbuf; } extra = NULL; action = fcmd_decode(cbuf, &extra); /* * If an "extra" string was returned, * process it as a string of command characters. */ if (extra != NULL) ungetsc(extra); } /* * Clear the cmdbuf string. * (But not if we're in the prefix of a command, * because the partial command string is kept there.) */ if (action != A_PREFIX) cmd_reset(); switch (action) { case A_DIGIT: /* * First digit of a number. */ start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE); goto again; case A_F_WINDOW: /* * Forward one window (and set the window size). */ if (number > 0) swindow = (int)number; /* FALLTHRU */ case A_F_SCREEN: /* * Forward one screen. */ if (number <= 0) number = get_swindow(); cmd_exec(); if (show_attn) set_attnpos(bottompos); forward((int)number, 0, 1); break; case A_B_WINDOW: /* * Backward one window (and set the window size). */ if (number > 0) swindow = (int)number; /* FALLTHRU */ case A_B_SCREEN: /* * Backward one screen. */ if (number <= 0) number = get_swindow(); cmd_exec(); backward((int)number, 0, 1); break; case A_F_LINE: /* * Forward N (default 1) line. */ if (number <= 0) number = 1; cmd_exec(); if (show_attn == OPT_ONPLUS && number > 1) set_attnpos(bottompos); forward((int)number, 0, 0); break; case A_B_LINE: /* * Backward N (default 1) line. */ if (number <= 0) number = 1; cmd_exec(); backward((int)number, 0, 0); break; case A_F_SKIP: /* * Skip ahead one screen, and then number lines. */ if (number <= 0) { number = get_swindow(); } else { number += get_swindow(); } cmd_exec(); if (show_attn == OPT_ONPLUS) set_attnpos(bottompos); forward((int)number, 0, 1); break; case A_FF_LINE: /* * Force forward N (default 1) line. */ if (number <= 0) number = 1; cmd_exec(); if (show_attn == OPT_ONPLUS && number > 1) set_attnpos(bottompos); forward((int)number, 1, 0); break; case A_BF_LINE: /* * Force backward N (default 1) line. */ if (number <= 0) number = 1; cmd_exec(); backward((int)number, 1, 0); break; case A_FF_SCREEN: /* * Force forward one screen. */ if (number <= 0) number = get_swindow(); cmd_exec(); if (show_attn == OPT_ONPLUS) set_attnpos(bottompos); forward((int)number, 1, 0); break; case A_F_FOREVER: /* * Forward forever, ignoring EOF. */ newaction = forw_loop(0); break; case A_F_UNTIL_HILITE: newaction = forw_loop(1); break; case A_F_SCROLL: /* * Forward N lines * (default same as last 'd' or 'u' command). */ if (number > 0) wscroll = (int)number; cmd_exec(); if (show_attn == OPT_ONPLUS) set_attnpos(bottompos); forward(wscroll, 0, 0); break; case A_B_SCROLL: /* * Forward N lines * (default same as last 'd' or 'u' command). */ if (number > 0) wscroll = (int)number; cmd_exec(); backward(wscroll, 0, 0); break; case A_FREPAINT: /* * Flush buffers, then repaint screen. * Don't flush the buffers on a pipe! */ clear_buffers(); /* FALLTHRU */ case A_REPAINT: /* * Repaint screen. */ cmd_exec(); repaint(); break; case A_GOLINE: /* * Go to line N, default beginning of file. */ if (number <= 0) number = 1; cmd_exec(); jump_back(number); break; case A_PERCENT: /* * Go to a specified percentage into the file. */ if (number < 0) { number = 0; fraction = 0; } if (number > 100) { number = 100; fraction = 0; } cmd_exec(); jump_percent((int)number, fraction); break; case A_GOEND: /* * Go to line N, default end of file. */ cmd_exec(); if (number <= 0) jump_forw(); else jump_back(number); break; case A_GOPOS: /* * Go to a specified byte position in the file. */ cmd_exec(); if (number < 0) number = 0; jump_line_loc((off_t) number, jump_sline); break; case A_STAT: /* * Print file name, etc. */ if (ch_getflags() & CH_HELPFILE) break; cmd_exec(); parg.p_string = eq_message(); error("%s", &parg); break; case A_VERSION: /* * Print version number, without the "@(#)". */ cmd_exec(); dispversion(); break; case A_QUIT: /* * Exit. */ if (curr_ifile != NULL_IFILE && ch_getflags() & CH_HELPFILE) { /* * Quit while viewing the help file * just means return to viewing the * previous file. */ hshift = save_hshift; if (edit_prev(1) == 0) break; } if (extra != NULL) quit(*extra); quit(QUIT_OK); break; /* * Define abbreviation for a commonly used sequence below. */ #define DO_SEARCH() \ if (number <= 0) number = 1; \ mca_search(); \ cmd_exec(); \ multi_search(NULL, (int)number); case A_F_SEARCH: /* * Search forward for a pattern. * Get the first char of the pattern. */ search_type = SRCH_FORW; if (number <= 0) number = 1; mca_search(); c = getcc(); goto again; case A_B_SEARCH: /* * Search backward for a pattern. * Get the first char of the pattern. */ search_type = SRCH_BACK; if (number <= 0) number = 1; mca_search(); c = getcc(); goto again; case A_FILTER: search_type = SRCH_FORW | SRCH_FILTER; mca_search(); c = getcc(); goto again; case A_AGAIN_SEARCH: /* * Repeat previous search. */ DO_SEARCH(); break; case A_T_AGAIN_SEARCH: /* * Repeat previous search, multiple files. */ search_type |= SRCH_PAST_EOF; DO_SEARCH(); break; case A_REVERSE_SEARCH: /* * Repeat previous search, in reverse direction. */ save_search_type = search_type; search_type = SRCH_REVERSE(search_type); DO_SEARCH(); search_type = save_search_type; break; case A_T_REVERSE_SEARCH: /* * Repeat previous search, * multiple files in reverse direction. */ save_search_type = search_type; search_type = SRCH_REVERSE(search_type); search_type |= SRCH_PAST_EOF; DO_SEARCH(); search_type = save_search_type; break; case A_UNDO_SEARCH: undo_search(); break; case A_HELP: /* * Help. */ if (ch_getflags() & CH_HELPFILE) break; if (ungot != NULL || unget_end) { error(less_is_more ? "Invalid option -p h" : "Invalid option ++h", NULL_PARG); break; } cmd_exec(); save_hshift = hshift; hshift = 0; (void) edit(FAKE_HELPFILE); break; case A_EXAMINE: /* * Edit a new file. Get the filename. */ if (secure) { error("Command not available", NULL_PARG); break; } start_mca(A_EXAMINE, "Examine: ", ml_examine, 0); c = getcc(); goto again; case A_VISUAL: /* * Invoke an editor on the input file. */ if (secure) { error("Command not available", NULL_PARG); break; } if (ch_getflags() & CH_HELPFILE) break; if (strcmp(get_filename(curr_ifile), "-") == 0) { error("Cannot edit standard input", NULL_PARG); break; } if (curr_altfilename != NULL) { error("WARNING: This file was viewed via " "LESSOPEN", NULL_PARG); } start_mca(A_SHELL, "!", ml_shell, 0); /* * Expand the editor prototype string * and pass it to the system to execute. * (Make sure the screen is displayed so the * expansion of "+%lm" works.) */ make_display(); cmd_exec(); lsystem(pr_expand(editproto, 0), NULL); break; case A_NEXT_FILE: /* * Examine next file. */ if (ntags()) { error("No next file", NULL_PARG); break; } if (number <= 0) number = 1; if (edit_next((int)number)) { if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) quit(QUIT_OK); parg.p_string = (number > 1) ? "(N-th) " : ""; error("No %snext file", &parg); } break; case A_PREV_FILE: /* * Examine previous file. */ if (ntags()) { error("No previous file", NULL_PARG); break; } if (number <= 0) number = 1; if (edit_prev((int)number)) { parg.p_string = (number > 1) ? "(N-th) " : ""; error("No %sprevious file", &parg); } break; case A_NEXT_TAG: if (number <= 0) number = 1; tagfile = nexttag((int)number); if (tagfile == NULL) { error("No next tag", NULL_PARG); break; } if (edit(tagfile) == 0) { off_t pos = tagsearch(); if (pos != -1) jump_loc(pos, jump_sline); } break; case A_PREV_TAG: if (number <= 0) number = 1; tagfile = prevtag((int)number); if (tagfile == NULL) { error("No previous tag", NULL_PARG); break; } if (edit(tagfile) == 0) { off_t pos = tagsearch(); if (pos != -1) jump_loc(pos, jump_sline); } break; case A_INDEX_FILE: /* * Examine a particular file. */ if (number <= 0) number = 1; if (edit_index((int)number)) error("No such file", NULL_PARG); break; case A_REMOVE_FILE: if (ch_getflags() & CH_HELPFILE) break; old_ifile = curr_ifile; new_ifile = getoff_ifile(curr_ifile); if (new_ifile == NULL_IFILE) { ring_bell(); break; } if (edit_ifile(new_ifile) != 0) { reedit_ifile(old_ifile); break; } del_ifile(old_ifile); break; case A_OPT_TOGGLE: optflag = OPT_TOGGLE; optgetname = FALSE; mca_opt_toggle(); c = getcc(); goto again; case A_DISP_OPTION: /* * Report a flag setting. */ optflag = OPT_NO_TOGGLE; optgetname = FALSE; mca_opt_toggle(); c = getcc(); goto again; case A_FIRSTCMD: /* * Set an initial command for new files. */ start_mca(A_FIRSTCMD, "+", NULL, 0); c = getcc(); goto again; case A_SHELL: /* * Shell escape. */ if (secure) { error("Command not available", NULL_PARG); break; } start_mca(A_SHELL, "!", ml_shell, 0); c = getcc(); goto again; case A_SETMARK: /* * Set a mark. */ if (ch_getflags() & CH_HELPFILE) break; start_mca(A_SETMARK, "mark: ", (void*)NULL, 0); c = getcc(); if (c == erase_char || c == erase2_char || c == kill_char || c == '\n' || c == '\r') break; setmark(c); break; case A_GOMARK: /* * Go to a mark. */ start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0); c = getcc(); if (c == erase_char || c == erase2_char || c == kill_char || c == '\n' || c == '\r') break; cmd_exec(); gomark(c); break; case A_PIPE: if (secure) { error("Command not available", NULL_PARG); break; } start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); c = getcc(); if (c == erase_char || c == erase2_char || c == kill_char) break; if (c == '\n' || c == '\r') c = '.'; if (badmark(c)) break; pipec = c; start_mca(A_PIPE, "!", ml_shell, 0); c = getcc(); goto again; case A_B_BRACKET: case A_F_BRACKET: start_mca(action, "Brackets: ", (void*)NULL, 0); c = getcc(); goto again; case A_LSHIFT: if (number > 0) shift_count = number; else number = (shift_count > 0) ? shift_count : sc_width / 2; if (number > hshift) number = hshift; hshift -= number; screen_trashed = 1; break; case A_RSHIFT: if (number > 0) shift_count = number; else number = (shift_count > 0) ? shift_count : sc_width / 2; hshift += number; screen_trashed = 1; break; case A_PREFIX: /* * The command is incomplete (more chars are needed). * Display the current char, so the user knows * what's going on, and get another character. */ if (mca != A_PREFIX) { cmd_reset(); start_mca(A_PREFIX, " ", (void*)NULL, CF_QUIT_ON_ERASE); (void) cmd_char(c); } c = getcc(); goto again; case A_NOACTION: break; default: ring_bell(); break; } } }
void Audio::start_audio() { if (!sound_enabled) { // Since many GNU/Linux distros are infected with PulseAudio, SDL2 could chose PA as first // driver option before ALSA, and PA doesn't obbey our sample number requests, resulting // in audio gaps, if we're on a GNU/Linux we force ALSA. // Else we accept whatever SDL2 wants to give us or what the user specifies on SDL_AUDIODRIVER // enviroment variable. std::string platform = SDL_GetPlatform(); if (platform=="Linux"){ if (SDL_InitSubSystem(SDL_INIT_AUDIO)!=0) { std::cout << "Error initalizing audio subsystem: " << SDL_GetError() << std::endl; } if (SDL_AudioInit("alsa")!=0) { std::cout << "Error initalizing audio using ALSA: " << SDL_GetError() << std::endl; return; } } else { if(SDL_Init(SDL_INIT_AUDIO) == -1) { std::cout << "Error initalizing audio: " << SDL_GetError() << std::endl; return; } } // SDL Audio Properties SDL_AudioSpec desired, obtained; desired.freq = FREQ; desired.format = AUDIO_S16SYS; desired.channels = CHANNELS; desired.samples = SAMPLES; desired.callback = fill_audio; desired.userdata = NULL; // SDL2 block dev = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, /*SDL_AUDIO_ALLOW_FORMAT_CHANGE*/0); if (dev == 0) { std::cout << "Error opening audio device: " << SDL_GetError() << std::endl; return; } if (desired.samples != obtained.samples) { std::cout << "Error initalizing audio: number of samples not supported." << std::endl << "Please compare desired vs obtained. Look at what audio driver SDL2 is using." << std::endl; return; } bytes_per_sample = CHANNELS * (BITS / 8); // Start Audio sound_enabled = true; // how many fragments in the dsp buffer const int DSP_BUFFER_FRAGS = 5; int specified_delay_samps = (FREQ * SND_DELAY) / 1000; int dsp_buffer_samps = SAMPLES * DSP_BUFFER_FRAGS + specified_delay_samps; dsp_buffer_bytes = CHANNELS * dsp_buffer_samps * (BITS / 8); dsp_buffer = new uint8_t[dsp_buffer_bytes]; // Create Buffer For Mixing uint16_t buffer_size = (FREQ / config.fps) * CHANNELS; mix_buffer = new uint16_t[buffer_size]; clear_buffers(); clear_wav(); SDL_PauseAudioDevice(dev,0); } }
extern "C" unsigned char rglswCreateWindow(GLint ihwnd, GLint width) { DDSURFACEDESC ddsd; HRESULT ddrval; DDPIXELFORMAT pix; DDSCAPS ddscaps; DDCAPS ddcaps; HWND hWnd = (HWND)ihwnd; SCRWIDTH = width; switch (width) { case 1600: SCRHEIGHT = 1200; break; case 1280: SCRHEIGHT = 1024; break; case 1024: SCRHEIGHT = 768; break; case 800: SCRHEIGHT = 600; break; default: SCRWIDTH = 640; SCRHEIGHT = 480; } hwnd = hWnd; ddrval = DirectDrawCreate(NULL, &lpDD, NULL); if (ddrval != DD_OK) { return FALSE; } ZeroMemory(&ddcaps, sizeof(ddcaps)); ddcaps.dwSize = sizeof(ddcaps); lpDD->GetCaps(&ddcaps, NULL); if (WINDOWED) { ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_NORMAL); if (ddrval != DD_OK) { return FALSE; } } else { ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if (ddrval != DD_OK) { return FALSE; } ddrval = lpDD->SetDisplayMode(SCRWIDTH, SCRHEIGHT, 16); if (ddrval != DD_OK) { return FALSE; } } ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); if (WINDOWED) { ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddrval = lpDD->CreateSurface(&ddsd, &PrimarySurface, NULL); } else { ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddrval = lpDD->CreateSurface(&ddsd, &PrimarySurface, NULL); } if (ddrval != DD_OK) { return FALSE; } ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; ddsd.dwWidth = SCRWIDTH; ddsd.dwHeight = SCRHEIGHT; ddrval = lpDD->CreateSurface(&ddsd, &BackSurface, NULL); if (ddrval != DD_OK) { ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddrval = lpDD->CreateSurface(&ddsd, &BackSurface, NULL); } if (ddrval != DD_OK) { return FALSE; } pix.dwSize = sizeof(pix); pix.dwFlags = DDPF_RGB; BackSurface->GetPixelFormat(&pix); if (pix.dwRBitMask == 0x7C00) { depth = 15; } else { depth = 16; } bActive = TRUE; if (useDirectDraw) { scratch_pitch = GetPitch(); scratch_buffer_2 = NULL; } else { depth = 15; scratch_pitch = 2*SCRWIDTH; scratch_buffer_2 = (BYTE*)malloc(scratch_pitch*SCRHEIGHT); } scratch_buffer = (BYTE*)malloc(scratch_pitch*SCRHEIGHT); memset(scratch_buffer, 0, scratch_pitch*SCRHEIGHT); clear_buffers(); return TRUE; }
Engine* engine_init_level (Context* context) { Engine* engine = (Engine*) malloc(sizeof(Engine)); engine->context = context; engine->tiles = load_tiles(context); int h, w, i; h = context->video[0]->head->v->bitmap->h; w = context->video[0]->head->v->bitmap->w; engine->partition_len = ceil((((double) w) / BOX_SIZE)) * ceil((((double) h) / BOX_SIZE)); engine->partitions = (Node**) malloc(engine->partition_len * sizeof(Node*)); memset(engine->partitions, 0, engine->partition_len * sizeof(Node*)); engine->flash_anims = linked_list_init(); for (i = 0; i < engine->partition_len; i++) { engine->partitions[i] = linked_list_init(); } engine->max_h = h; engine->max_w = w; // Clear any and all vertexes left on the screen (including the background) clear_buffers(context); engine->loading_bufs = engine_create_loading(context, h, w); engine_init_bg(engine, h, w); engine_inc_loading(engine); engine->explosion = engine_load_explosion(context, engine); engine->explosions = linked_list_init(); engine->explo_field = 0; engine->tbl_count = 0; engine->player_tbl = (Player**) malloc(TBL_MAX * sizeof(Player*)); engine->player = engine_load_player( context , engine , "ship" , w / 2 , h - SCREEN_TOP ); engine_inc_loading(engine); engine->shot_bufs = engine_init_shots(context, engine, h); engine->shot_field = 0ULL; engine->enemy_sprites = engine_load_enemies(context, engine); engine->shield_bufs = engine_init_shield(context, engine); engine->score_bufs = engine_init_score(context, h); engine->enemies = (Player**) malloc(MAX_ENEMIES * sizeof(Player*)); memset(engine->enemies, 0, MAX_ENEMIES * sizeof(Player*)); engine->enemy_field = 0; context->game_state = TYRIAN_GAME_LEVEL; engine_clear_loading(context, engine); #if DEBUG vertex* v; fps = (vertex_buffer**) malloc(6 * sizeof(vertex_buffer*)); char str[7] = "FPS 00"; for (i = 0; i < 6; i++) { v = vertex_create( w - GLYPH_SIZE * (6 - i) , SCREEN_TOP , context->glyphs->map[char2index(str[i])] ); context->video[1] = vertex_buffer_push(context->video[1], v); fps[i] = context->video[1]->prev; } #endif return engine; }
int gfx_step( uint32_t *fifo, uint32_t jmp, int off ) { static bool init_particles = false; if( !init_particles ) { init_particles = true; for( size_t i = 0; i < INUMBER; ++i ) { dt[i] = ( rand() & 63 ) + 32; rnds[i][0] = 360.0f * i / (float)( INUMBER );//rnd( 0.0f, 360.0f ); rnds[i][1] = rnd( -0.2f, +0.2f ); rnds[i][2] = rnd( -0.8f, +0.3f ); rnds[i][3] = rnd( 0.3f, 1.0f ); insts[i].time = rand(); insts[i].col[0] = rnd( 0.8f, 1.0f ); insts[i].col[1] = rnd( 0.8f, 1.0f ); insts[i].col[2] = rnd( 0.8f, 1.0f ); insts[i].col[3] = 1.0f; } } for( size_t i = 0; i < INUMBER; ++i ) { insts[i].time += dt[i]; identity( insts[i].mat ); rotatef( 80.0f, 1.0f, 0.0f, 0.0f, insts[i].mat ); rotatef( off * 0.5f + rnds[i][0], 0.0f, 0.0f, 1.0f, insts[i].mat ); translatef( 1.6f, rnds[i][1], rnds[i][2], insts[i].mat ); scalef( rnds[i][3], insts[i].mat ); float d = insts[i].mat[11]; d = ( 1.0f - 0.6f * d ); insts[i].scale = rnds[i][3]; insts[i].col[0] = d; insts[i].col[1] = 0.5f + d; insts[i].col[2] = d; //translatef( 1.0f * sin( t * rnds[i][0] ), 1.0f * cos( t * rnds[i][0] ), 1.0f * sin( t * rnds[i][2] ), insts[i].mat ); } clear_buffer_t clear; clear.clearR = clear.clearG = clear.clearB = clear.clearA = clear.clearD = 1; clear.rgba = 50 + ( 10 << 8 ) + ( 5 << 16 ); clear.depth = 0xffff; static job_t job; static size_t curr = 0x0; job.pd.insts = (uint32_t)insts; job.pd.isize = INUMBER; job.pd.dynamic = (uint32_t)( dynamic ) + curr * 24; job.pd.fx = (uint32_t)fx.get_data(); job.pd.atlas = (uint32_t)atlas.get_data(); job.pd.asize = atlas.get_size(); job.kick_job( ); job.join(); uint32_t *ptr = fifo; static float angle = 180.0f; ptr += setup_surfaces_with_offset( ptr, off % 3 ); ptr += clear_buffers( &clear, ptr, Nv3D ); ptr += set_mvp( ptr, angle ); ptr += set_cnst( ptr ); //ptr += troll_texture.set( ptr ); //ptr += troll.set( ptr ); //ptr += custom.set( ptr ); ptr += particles.set( ptr ); ptr += particle_texture.set( ptr ); ptr += draw_primitives( 0, QUADS, curr, job.pd.quads * 4, ptr, Nv3D ); curr += job.pd.quads * 4;// + 128; curr = ( curr + 16 ) & 2047; //printf( "%d \n", job.pd.quads ); ptr += jump_to_address( ptr, jmp ); return ptr - fifo; }
// check for replies from sensor, returns true if at least one message was processed bool AP_Proximity_LightWareSF40C::check_for_reply() { if (uart == nullptr) { return false; } // read any available lines from the lidar // if CR (i.e. \r), LF (\n) it means we have received a full packet so send for processing // lines starting with # are ignored because this is the echo of a set-motor request which has no reply // lines starting with ? are the echo back of our distance request followed by the sensed distance // distance data appears after a <space> // distance data is comma separated so we put into separate elements (i.e. <space>angle,distance) uint16_t count = 0; int16_t nbytes = uart->available(); while (nbytes-- > 0) { char c = uart->read(); // check for end of packet if (c == '\r' || c == '\n') { if ((element_len[0] > 0)) { if (process_reply()) { count++; } } // clear buffers after processing clear_buffers(); ignore_reply = false; wait_for_space = false; // if message starts with # ignore it } else if (c == '#' || ignore_reply) { ignore_reply = true; // if waiting for <space> } else if (c == '?') { wait_for_space = true; } else if (wait_for_space) { if (c == ' ') { wait_for_space = false; } // if comma, move onto filling in 2nd element } else if (c == ',') { if ((element_num == 0) && (element_len[0] > 0)) { element_num++; } else { // don't support 3rd element so clear buffers clear_buffers(); ignore_reply = true; } // if part of a number, add to element buffer } else if (isdigit(c) || c == '.' || c == '-') { element_buf[element_num][element_len[element_num]] = c; element_len[element_num]++; if (element_len[element_num] >= sizeof(element_buf[element_num])-1) { // too long, discard the line clear_buffers(); ignore_reply = true; } } } return (count > 0); }