emu_state * init_emulator(const char *bootrom_path, const char *rom_path, const char *save_path) { emu_state *state = (emu_state *)calloc(1, sizeof(emu_state)); cart_header *header; if(!rom_path) { error(state, "Unspecified ROM path!"); return NULL; } if(save_path && strcmp(rom_path, save_path) == 0) { error(state, "Save path can't be the same as ROM path (ignoring)"); save_path = NULL; } if(bootrom_path && ((save_path && strcmp(bootrom_path, save_path) == 0) || strcmp(bootrom_path, rom_path) == 0)) { warning(state, "Boot ROM path cannot be same as ROM path or save path (ignoring)"); bootrom_path = NULL; } state->save_path = save_path ? strdup(save_path) : NULL; state->interrupts.enabled = true; state->wait = 1; state->freq = CPU_FREQ_DMG; state->step_core = 1; if(unlikely(!read_rom_data(state, rom_path, &header))) { error(state, "Can't read ROM data (ROM is corrupt)?"); free(state); return NULL; } if(bootrom_path) { if(!read_bootrom_data(state, bootrom_path)) { warning(state, "Can't read boot ROM data, continuing without it"); } else { state->in_bootrom = true; } } // Initalise state init_ctl(state); init_lcdc(state); // Start the clock state->start_time = get_time(); state->next_vblank_time = state->start_time + NSEC_PER_VBLANK; return state; }
void tl_init_triode(tl_arglist *args){ tl_procession *procession; // for dac // check for a procession in the args if(args->argv[0]->type!=TL_PROCESSION) { printf("error: tl_init_moog_abuse: first init argument needs to be a valid procession pointer\n"); return; } else procession = args->argv[0]->procession; // initialize solver: solver = tl_init_UDS_solver(0, // ins 1, // 1); // upsampling (not yet implemented) // dac: dac = tl_init_dac(procession, 2, 1); // adc: adc = tl_init_adc(procession, 1, 1); solver->inlets[0] = adc->outlets[0]; // control interface: ctls = init_ctl(TL_HEAD_CTL); // init ctls here // init controls b_reset = init_ctl(TL_BANG_CTL); b_reset->name = name_new("reset"); b_reset->bang_func = reset; install_onto_ctl_list(ctls, b_reset); // hook up to dac dac->inlets[0] = solver->outlets[0]; dac->inlets[1] = adc->outlets[0]; }
int setup(void){ int i, cnt = 5000; tl_class *class_list; // initialize globals ... rethink this tl_set_samplerate(44100); tl_set_block_len(64); set_g_lvl_stck(init_lvl_stck()); set_g_ctl_head(init_ctl(TL_HEAD_CTL)); // TODO: attach these to modules, I can't see // any reason not to do this and automate this whole process ctl_l_freq = init_ctl(TL_LIN_CTL); ctl_r_freq = init_ctl(TL_LIN_CTL); ctl_l_freq->is_verbose = 0; ctl_r_freq->is_verbose = 0; ctl_l_amp = init_ctl(TL_LIN_CTL); ctl_r_amp = init_ctl(TL_LIN_CTL); ctl_l_amp->is_verbose = 1; ctl_r_amp->is_verbose = 1; install_onto_ctl_list(get_g_ctl_head(), ctl_l_freq); install_onto_ctl_list(get_g_ctl_head(), ctl_r_freq); install_onto_ctl_list(get_g_ctl_head(), ctl_l_amp); install_onto_ctl_list(get_g_ctl_head(), ctl_r_amp); // initialize portaudio pa_initialize(0,0,2,2,.25); // setup the modules dac = (tl_dac *)tl_init_dac(2,1); // dac will initialize the global output buffer return 0; }
tl_procession *init_procession(void){ tl_procession *x = malloc(sizeof(tl_procession)); x->class_head = init_class(); x->ctl_head = init_ctl(TL_HEAD_CTL); x->lvl_stck = init_lvl_stck(); x->ab_in = init_audio_buff(TL_MAXCHANNS); x->ab_out = init_audio_buff(TL_MAXCHANNS); return x; }
static int __init htty_init(void) { int retval; int i; pr_info(DRIVER_DESC " init in>>>\n"); /* allocate the tty driver */ tty_driver = alloc_tty_driver(CMINORS); if (!tty_driver) return -ENOMEM; /* initialize the tty driver */ tty_driver->owner = THIS_MODULE; tty_driver->driver_name = "htty"; tty_driver->name = "htty"; tty_driver->major = H_TTY_MAJOR, tty_driver->type = TTY_DRIVER_TYPE_SERIAL, tty_driver->subtype = SERIAL_TYPE_NORMAL, tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; tty_driver->flags |= TTY_DRIVER_UNNUMBERED_NODE; tty_driver->init_termios = tty_std_termios; tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty_set_operations(tty_driver, &serial_ops); // register the tty driver retval = tty_register_driver(tty_driver); if (retval) { printk(KERN_ERR "failed to register htty tty driver"); put_tty_driver(tty_driver); return retval; } init_ctl(); init_chtty(); for(i=0;i<CMINORS;i++){ htty_table[i]=NULL; } pr_info(DRIVER_DESC " init out<<<\n"); pr_info(DRIVER_DESC DRIVER_VERSION "\n"); return retval; }
//int main(void) { ////main function int main (void) { u32 waitForCard = 0; // set up avr32 hardware and peripherals init_avr32(); print_dbg("\r\n SRAM size: 0x"); print_dbg_hex(smc_get_cs_size(1)); cpu_irq_disable(); /// test the SRAM sram_test(); cpu_irq_enable(); //memory manager init_mem(); print_dbg("\r\n init_mem"); // wait for sdcard print_dbg("\r\n SD check... "); while (!sd_mmc_spi_mem_check()) { waitForCard++; } print_dbg("\r\nfound SD card. "); // intialize the FAT filesystem print_dbg("\r\n init fat"); fat_init(); // setup control logic print_dbg("\r\n init ctl"); init_ctl(); /* // initialize the application */ /* app_init(); */ /* print_dbg("\r\n init app"); */ // initialize flash: firstrun = init_flash(); print_dbg("r\n init flash, firstrun: "); print_dbg_ulong(firstrun); screen_startup(); // find and load dsp from sdcard files_search_dsp(); print_dbg("\r\n starting event loop.\r\n"); // dont do startup startup = 0; while(1) { check_events(); } }
// init func void tl_init_lotka_volt(tl_arglist *args){ tl_procession *procession; // needed for DAC // check for a procession in the args if(args->argv[0]->type!=TL_PROCESSION) { printf("error: tl_init_fm : first init argument needs to be a valid procession pointer\n"); return; } else procession = args->argv[0]->procession; // initialize the solver solver = tl_init_UDS_solver(2, N_NODES, 1); // we need a dac, so make one dac = tl_init_dac(procession, N_NODES, 1); // initialize the local ctl list head lotka_volt_head = init_ctl(TL_HEAD_CTL); // initialize lotka_volt solver nodes prey_node = tl_init_UDS_node(prey_dot, N_NODES, 1); tl_reset_UDS_node(prey_node, 0.0); tl_push_UDS_node(solver->UDS_net, prey_node); pred_node = tl_init_UDS_node(pred_dot, N_NODES, 1); tl_reset_UDS_node(pred_node, 0.0); tl_push_UDS_node(solver->UDS_net, pred_node); // hook up the inlets and outlets pred_node->data_in[0] = prey_node->data_out; pred_node->data_in[1] = pred_node->data_out; prey_node->data_in[0] = prey_node->data_out; prey_node->data_in[1] = pred_node->data_out; // ctl setup int i; char buf[50]; k_alpha = init_ctl(TL_LIN_CTL); sprintf(buf, "k_alpha"); k_alpha->name = name_new(buf); set_ctl_val(k_alpha, 0); install_onto_ctl_list(lotka_volt_head, k_alpha); k_beta = init_ctl(TL_LIN_CTL); sprintf(buf, "k_beta"); k_beta->name = name_new(buf); set_ctl_val(k_beta, 0); install_onto_ctl_list(lotka_volt_head, k_beta); k_delta = init_ctl(TL_LIN_CTL); sprintf(buf, "k_delta"); k_delta->name = name_new(buf); set_ctl_val(k_delta, 0); install_onto_ctl_list(lotka_volt_head, k_delta); k_gamma = init_ctl(TL_LIN_CTL); sprintf(buf, "k_gamma"); k_gamma->name = name_new(buf); set_ctl_val(k_gamma, 0); install_onto_ctl_list(lotka_volt_head, k_gamma); k_m0 = init_ctl(TL_LIN_CTL); sprintf(buf, "k_m0"); k_m0->name = name_new(buf); set_ctl_val(k_m0, 0); install_onto_ctl_list(lotka_volt_head, k_m0); k_m1 = init_ctl(TL_LIN_CTL); sprintf(buf, "k_m1"); k_m1->name = name_new(buf); set_ctl_val(k_m1, 0); install_onto_ctl_list(lotka_volt_head, k_m1); for(i=0;i<N_NODES;i++) { k_states[i] = init_ctl(TL_LIN_CTL); sprintf(buf, "k_states_%d", i); k_states[i]->name = name_new(buf); set_ctl_val(k_states[i], 0); install_onto_ctl_list(lotka_volt_head, k_states[i]); } // set up the set function b_set_lotka_volt = init_ctl(TL_BANG_CTL); b_set_lotka_volt->name = name_new("set_lotka_volt_states"); b_set_lotka_volt->bang_func = set_lotka_volt; install_onto_ctl_list(lotka_volt_head, b_set_lotka_volt); // hookup oulets to dac for(i=0;i<N_NODES;i++) dac->inlets[i] = solver->outlets[i]; }
static tl_UDS_osc *init_UDS_osc(int which){ tl_UDS_osc *x = malloc(sizeof(tl_UDS_osc)); char buf[50]; int i; // initialize the nodes x->sin_node = tl_init_UDS_node(osc_sin, osc_cnt*2, 1); x->cos_node = tl_init_UDS_node(osc_cos, osc_cnt*2, 1); // initialize the controls x->k_osc_freq = init_ctl(TL_LIN_CTL); sprintf(buf, "k_osc_freq_%d", which); x->k_osc_freq->name = name_new(buf); set_ctl_val(x->k_osc_freq, 440); install_onto_ctl_list(osc_head, x->k_osc_freq); x->k_sync_thresh = init_ctl(TL_LIN_CTL); sprintf(buf, "k_sync_thresh_%d", which); x->k_sync_thresh->name = name_new(buf); set_ctl_val(x->k_sync_thresh, .9); install_onto_ctl_list(osc_head, x->k_sync_thresh); x->k_delta = init_ctl(TL_LIN_CTL); sprintf(buf, "k_delta_%d", which); x->k_delta->name = name_new(buf); set_ctl_val(x->k_delta, 0); install_onto_ctl_list(osc_head, x->k_delta); x->k_sync_g = init_ctl(TL_LIN_CTL); sprintf(buf, "k_sync_g_%d", which); x->k_sync_g->name = name_new(buf); set_ctl_val(x->k_sync_g, 1); install_onto_ctl_list(osc_head, x->k_sync_g); x->k_alpha = init_ctl(TL_LIN_CTL); sprintf(buf, "k_alpha_%d", which); x->k_alpha->name = name_new(buf); set_ctl_val(x->k_alpha, 0); install_onto_ctl_list(osc_head, x->k_alpha); x->k_beta = init_ctl(TL_LIN_CTL); sprintf(buf, "k_beta_%d", which); x->k_beta->name = name_new(buf); set_ctl_val(x->k_beta, 0); install_onto_ctl_list(osc_head, x->k_beta); for(i=0;i<osc_cnt;i++) { x->k_mod_depth[i] = init_ctl(TL_LIN_CTL); sprintf(buf, "k_mod_depth_%d_%d", which,i); x->k_mod_depth[i]->name = name_new(buf); set_ctl_val(x->k_mod_depth[i], 0); install_onto_ctl_list(osc_head, x->k_mod_depth[i]); } for(i=0;i<osc_cnt;i++) { x->k_gamma[i] = init_ctl(TL_LIN_CTL); sprintf(buf, "k_gamma_%d_%d", which,i); x->k_gamma[i]->name = name_new(buf); set_ctl_val(x->k_gamma[i], 0); install_onto_ctl_list(osc_head, x->k_gamma[i]); } // the other variables x->is_sync = 0; x->which = which; // stack the ctls together /* x->k_osc_freq->next = x->k_sync_thresh; */ /* x->k_sync_thresh->next = x->k_delta; */ /* x->k_delta->next = x->k_sync_g; */ /* x->k_sync_g->next = x->k_alpha; */ /* x->k_alpha->next = x->k_beta; */ /* x->k_beta->next = x->k_gamma[0]; */ /* //x->k_sync_g->next = x->k_mod_depth[0]; */ /* for(i=1;i<osc_cnt;i++) */ /* x->k_mod_depth[i-1]->next = x->k_mod_depth[i]; */ x->alphas = malloc(sizeof(tl_smp)*osc_cnt*tl_get_block_len()); for(i=0;i<osc_cnt*tl_get_block_len();i++) x->alphas[i] = 0; // copy the top ctl ptr into the node stuctures x->sin_node->ctls = x->k_osc_freq; x->cos_node->ctls = x->k_osc_freq; // copy them all into the global ctl processor /* install_onto_ctl_list(osc_head, x->k_osc_freq); */ return x; }
// init func void tl_init_fm_duff(tl_arglist *args){ int i, j; tl_procession *procession; // needed for DAC // check for a procession in the args if(args->argv[0]->type!=TL_PROCESSION) { printf("error: tl_init_fm : first init argument needs to be a valid procession pointer\n"); return; } else procession = args->argv[0]->procession; // initialize the solver solver = tl_init_UDS_solver(0, osc_cnt*2, 1); // we need a dac, so make one dac = tl_init_dac(procession, osc_cnt*2, 1); // initialize the local ctl list head osc_head = init_ctl(TL_HEAD_CTL); // initialize the oscillator parts oscs = malloc(sizeof(tl_UDS_osc *) * osc_cnt); for(i=0;i<osc_cnt; i++) { // initialize oscs[i] = init_UDS_osc(i); // install into the solver oscs[i]->sin_node->extra_data = (void *)oscs[i]; oscs[i]->cos_node->extra_data = (void *)oscs[i]; tl_push_UDS_node(solver->UDS_net, oscs[i]->sin_node); tl_push_UDS_node(solver->UDS_net, oscs[i]->cos_node); } for(i=0;i<osc_cnt*2; i++) dac->inlets[i] = solver->outlets[i]; reset_oscs(); // initialize the oscillators' states // connect the outlet of each oscillator to a each inlet on each one // including its own int k; for(i=0;i<osc_cnt;i++) { k = 0; for(j=0;j<osc_cnt*2;j+=2) { // arrange the inputs in the same order for each oscillator oscs[i]->sin_node->data_in[j] = oscs[k]->sin_node->data_out; oscs[i]->cos_node->data_in[j] = oscs[k]->sin_node->data_out; oscs[i]->sin_node->data_in[j+1] = oscs[k]->cos_node->data_out; oscs[i]->cos_node->data_in[j+1] = oscs[k++]->cos_node->data_out; } } // define the reset function bang ctl b_reset = init_ctl(TL_BANG_CTL); b_reset->name = name_new("reset_fm_oscs"); b_reset->bang_func = reset_oscs; install_onto_ctl_list(osc_head, b_reset); tl_ctl *next_toggle; char buf[50]; int cnt = 0; next_toggle = b_sync_toggle; for(i=0;i<osc_cnt;i++) for(j=0;j<osc_cnt;j++) { // initialize the control with appropriate name sprintf(buf, "b_sync_toggle_%d_%d",i+1, j+1); next_toggle = init_ctl(TL_BANG_CTL); next_toggle->name = name_new(buf); // give it a numeric tag toggle_data[cnt][0] = i; toggle_data[cnt][1] = j; // set the bang function next_toggle->bang_func = set_sync_matrix; // assign the tag set_ctl_bang_data(next_toggle, (void *)toggle_data[cnt++]); //printf("tl_init_fm: %p %p\n",toggle_data, next_toggle->bang_data); // install the current ctl install_onto_ctl_list(osc_head, next_toggle); } for(i=0;i<osc_cnt;i++) for(j=0;j<osc_cnt;j++) sync_matrix[i][j] = 0; }
int setup(void){ int i, cnt = 5000; tl_class *class_list; // initialize globals ... rethink this tl_set_samplerate(44100); tl_set_block_len(64); set_g_lvl_stck(init_lvl_stck()); set_g_ctl_head(init_ctl(TL_HEAD_CTL)); // TODO: attach these to modules, I can't see // any reason not to do this and automate this whole process ctl_l_freq = init_ctl(TL_LIN_CTL); ctl_r_freq = init_ctl(TL_LIN_CTL); ctl_l_freq->is_verbose = 0; ctl_r_freq->is_verbose = 0; ctl_l_amp = init_ctl(TL_LIN_CTL); ctl_r_amp = init_ctl(TL_LIN_CTL); ctl_l_amp->is_verbose = 1; ctl_r_amp->is_verbose = 1; install_onto_ctl_list(get_g_ctl_head(), ctl_l_freq); install_onto_ctl_list(get_g_ctl_head(), ctl_r_freq); install_onto_ctl_list(get_g_ctl_head(), ctl_l_amp); install_onto_ctl_list(get_g_ctl_head(), ctl_r_amp); // initialize portaudio pa_initialize(0,0,2,2,.25); // setup the modules dac = (tl_dac *)tl_init_dac(2,1); // dac will initialize the global output buffer tbl_l = (tl_table *)tl_init_table(1000, 1); tbl_r = (tl_table *)tl_init_table(1000, 1); lkup_l = (tl_lookup *)tl_init_lookup(1); lkup_r = (tl_lookup *)tl_init_lookup(1); osc_l = init_osc(tbl_l, lkup_l, ctl_l_freq->outlet, ctl_l_amp->outlet); osc_r = init_osc(tbl_r, lkup_r, ctl_r_freq->outlet, ctl_r_amp->outlet); // this part needs to be done explicitly // first, register the ctls set_ctl_kr(ctl_l_freq, &l_freq_val); set_ctl_kr(ctl_r_freq, &r_freq_val); set_ctl_kr(ctl_l_amp, &l_amp_val); set_ctl_kr(ctl_r_amp, &r_amp_val); // now register the classes set_g_class_head(init_class()); tl_install_class(get_g_class_head(), (void *)osc_l, osc_l->dsp_func, osc_l->kill_func); tl_install_class(get_g_class_head(), (void *)osc_r, osc_r->dsp_func, osc_r->kill_func); tl_install_class(get_g_class_head(), (void *)dac, dac->dsp_func, dac->kill_func); // connect to the dac dac->inlets[0] = osc_l->tbl->outlets[0]; dac->inlets[1] = osc_r->tbl->outlets[0]; return 0; }