ad_t ad_config (unsigned int mps, unsigned int kpc, unsigned int adqm){ bool result = false; unsigned char N = 0; ad_t ad = NULL; ad = ad_create(); assert(ad!=NULL); /* Modo PC para configurarlo */ ad_set_modo_pc(ad); /* Configuracion de la cantidad de muestras por segundo. */ if(mps < 10000000 && mps > 39215){ N = 10000000/mps; result = direccion(0x0c); if(!result) result = escritura(255-N); if(!result) result = direccion(0x0d); if(!result) result = escritura(0x00); }else { printf("Error en la cantidad de muestras por segundo\n"); return NULL; } assert(kpc==1 || kpc==2 || kpc==4 || kpc==8 || kpc==16 || kpc==32 || kpc==64); /* modo continuo -> b1 = 1. Modo modulado -> b1 = 0 */ if(adqm == AD_MODO_CONTINUO){ ad->conf = ad->conf | 0x02; ad->modo = AD_MODO_CONTINUO; } /* Kpc = tamano del buffer de adquisicion en Kb: */ if(kpc==64){ ad->conf = ad->conf|0x70; }else if(kpc==32){ ad->conf = ad->conf|0x60; }else if(kpc==16){ ad->conf = ad->conf|0x50; }else if(kpc==8){ ad->conf = ad->conf|0x40; }else if(kpc==4){ ad->conf = ad->conf|0x30; }else if(kpc==2){ ad->conf = ad->conf|0x20; }else if(kpc==1){ ad->conf = ad->conf|0x10; }else if(kpc != 0){ result = 1; } ad->canala = calloc(kpc*1024, sizeof(int)); ad->canalb = calloc(kpc*1024, sizeof(int)); ad->kpc = kpc; if(!result) result = direccion(0x0b); if(!result){ result = escritura(ad->conf); } ad_resetear_contador(ad); ad_set_modo_ad(ad); return ad; }
int racinix_start() { //vg_exit(); // Fix darker colors first time the mode is changed. vg_init(RACINIX_VIDEO_MODE); vbe_get_mode_info(RACINIX_VIDEO_MODE, &vmi); mouse_position = vectorCreate(vmi.XResolution / 2, vmi.YResolution / 2); // Initialize pointers to NULL so that in case of error the program is terminated properly. race = NULL; bitmap_background = NULL; bitmap_mouse_cursor = NULL; bitmap_red_car = NULL; bitmap_blue_car = NULL; bitmap_credits = NULL; bitmap_speedometer = NULL; font_impact = NULL; ad = NULL; bitmap_background = bitmap_load(RACINIX_FOLDER_IMAGES "background.bmp"); if (bitmap_background == NULL) { return 1; } bitmap_mouse_cursor = bitmap_load(RACINIX_FOLDER_IMAGES "cursor.bmp"); if (bitmap_mouse_cursor == NULL) { return 1; } bitmap_red_car = bitmap_load(RACINIX_FOLDER_IMAGES "red_car.bmp"); if (bitmap_red_car == NULL) { return 1; } bitmap_blue_car = bitmap_load(RACINIX_FOLDER_IMAGES "blue_car.bmp"); if (bitmap_blue_car == NULL) { return 1; } bitmap_credits = bitmap_load(RACINIX_FOLDER_IMAGES "credits.bmp"); if (bitmap_credits == NULL) { return 1; } bitmap_speedometer = bitmap_load(RACINIX_FOLDER_IMAGES "speedometer.bmp"); if (bitmap_speedometer == NULL) { return 1; } font_impact = font_load(RACINIX_FOLDER_FONTS "impact"); if (font_impact == NULL) { return 1; } if ((ad = ad_create(RACINIX_FILE_ADS, 120, font_impact, RACINIX_COLOR_ORANGE)) == NULL) { return 1; } vehicle_keys[0].accelerate = KEY_W; vehicle_keys[0].brake = KEY_S; vehicle_keys[0].turn_left = KEY_A; vehicle_keys[0].turn_right = KEY_D; vehicle_keys[1].accelerate = KEY_ARR_UP; vehicle_keys[1].brake = KEY_ARR_DOWN; vehicle_keys[1].turn_left = KEY_ARR_LEFT; vehicle_keys[1].turn_right = KEY_ARR_RIGHT; vehicle_colors[0] = VIDEO_GR_RED; vehicle_colors[1] = VIDEO_GR_BLUE; vehicle_bitmaps[0] = bitmap_red_car; vehicle_bitmaps[1] = bitmap_blue_car; if (racinix_dispatcher()) { return 1; } return 0; }