//get free bv id for a new route - returns 32 (DVDRP_INVALID_BV_ID) if //no free bv static uint8_t dvdrp_get_free_bv(uint8_t additional) { uint32_t bv = 0; uint8_t i, j; //first marked all used bits if(additional != DVDRP_INVALID_BV_ID) { mask_set(bv, additional); } for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(route_tbl[i].pred) { mask_set(bv, route_tbl[i].bv_pos); } } //now find free bv j = 0; if(bv == 0xFFFF) { //we're full, so sorry i = DVDRP_INVALID_BV_ID; } else { i = rand() % 32; for( ; j < 32; ++j) { if(!mask_set(bv, (i + j) % 32)) { break; } } } return (i + j) % 32; }
static void lightout_paint(struct module_configuration *mc, cairo_surface_t *cs) { unsigned width=mc->board_width, height=mc->board_height; if(!cs) { if(mc->verbose) { fprintf(stderr, "%s():ignoring paint because surface is NULL.\n", __func__); } return; } if(mc->use_shaped) { mask_surface_check(cs, width, height); assert(mask_surface != NULL); /* construct a mask */ if(mc->verbose) { fprintf(stderr, "%s():drawing the mask\n", __func__); } draw(mc, mask_surface, 1); /* uses XShapeCombineMask */ mask_set(cs, mask_surface); } /* draw the real thing */ if(mc->verbose) { fprintf(stderr, "%s():drawing the graphics\n", __func__); } draw(mc, cs, 0); }
static inline void fp_add_start_runnable(struct sched_thd *t) { struct sched_thd *head; u16_t p = sched_get_metric(t)->priority; assert(sched_thd_ready(t)); head = &priorities[p].runnable; ADD_LIST(head, t, prio_next, prio_prev); mask_set(p); }
static void dvdrp_get_splitbv(dvdrp_mesg_pkt *pkt, uint32_t *bv) { uint8_t i; *bv = 0; for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(dvdrp_match(pkt, &route_tbl[i])) { mask_set(*bv, route_tbl[i].bv_pos); } } }
static inline void fp_move_end_runnable(struct sched_thd *t) { struct sched_thd *head; unsigned short int p = sched_get_metric(t)->priority; assert(sched_thd_ready(t)); assert(!sched_thd_suspended(t)); head = &priorities[p].runnable; REM_LIST(t, prio_next, prio_prev); ADD_LIST(LAST_LIST(head, prio_next, prio_prev), t, prio_next, prio_prev); mask_set(p); }
void pool_free(mem_pool *pool, void *mem) { uint8_t bit; bit = (mem - pool->pool) / pool->type_size; mask_set(pool->free_vec, bit); }
static uint8_t dvdrp_mesg_send(dvdrp_mesg_pkt *dvdrp_ptr, comBuf *pkt) { node_id_t cur_next_hop = 0; //to make build clean uint32_t /*global,*/ local_bv; uint8_t global; uint8_t i, ret; // Add the proto ID to the end of the packet. pkt->data[pkt->size++] = DVDRP_PROTO_ID; // This is a rather rough function to write without dynamicly // sized DSs, so here it is unoptimized: // 1) create a global bit vector marked with matching routes // 2) take the first marked route and record it's next_hop // 3) unmark that route from the global bv ---\ !! // 4) mark in the local bv ---/ now rolled into step 5! // 5) iterate through the rest of the marked routes // a) if next_hop is the same, repeat 3 & 4 for route // 6) local bv is packets bvs; assign and send out // 7) goto 2 // // This strategy, while slow, saves on the need for larger arrays // or other memory hungary data structures. We can pay for // smaller memory size with a little bit of energy. // // Note: I've looked at the asm for this function and it's horrid. // avr-libc's 32-bit number support isn't poor, but rather I // didn't realize what an impact emulating 32-bit operations would // have. This function will need to get a serious facelift soon. // If the use of global can be reduced by doing inline marking in // the route table, or some other method, it'll be a major victory // toward reducing the size. // 1) global = 0; ret = FALSE; for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(route_tbl[i].receiver_id != DVDRP_INVALID_NODE_ID && mask_query(dvdrp_ptr->split_bv, route_tbl[i].bv_pos)) { // printf(".r;%d:%C", route_tbl[i].receiver_id, route_tbl[i].bv_pos); mask_set(global, i); } } // 2) while(1) { for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(mask_query(global, i)) { cur_next_hop = route_tbl[i].paths[0].next_hop; break; } } if(i == DVDRP_RT_MAX_PREDICATES) { // printf(".outp"); break; } // 5) local_bv = 0; for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { // 5a) if(mask_query(global, i) && cur_next_hop == route_tbl[i].paths[0].next_hop) { // 5a - 3) mask_unset(global, i); // 5a - 4) mask_set(local_bv, route_tbl[i].bv_pos); } } //check for local delivery if(cur_next_hop == node_id) { ret = TRUE; // printf(".mf;l"); } else { dvdrp_ptr->immed_dest = cur_next_hop; dvdrp_ptr->split_bv = local_bv; // printf(".mf;%d", dvdrp_ptr->immed_dest); com_send(IFACE_RADIO, pkt); //mos_led_toggle(1); } } // printf(".pts;%d\n", mos_check_stack(mos_thread_current())); return ret; }
int str_to_mask (Mask *mask, const char *orig, char **rejects) { char *ptr, *rest; int len, i, neg; int warn = 0; char * str; size_t cluep = 0; mask_unsetall(mask); if (!orig) return 0; /* Whatever */ if (rejects == NULL || *rejects != NULL) panic(1, "str_to_mask: rejects must be a pointer to null"); str = LOCAL_COPY(orig); while ((str = next_arg(str, &rest)) != NULL) { while (str) { if ((ptr = strchr(str, ',')) != NULL) *ptr++ = 0; if ((len = strlen(str)) != 0) { if (my_strnicmp(str, "ALL", len) == 0) mask_setall(mask); else if (my_strnicmp(str, "NONE", len) == 0) mask_unsetall(mask); else { if (*str == '-') { str++, len--; neg = 1; } else neg = 0; for (i = 0; i < level_bucket->numitems; i++) { if (!my_strnicmp(str, LEVELNAME(i), len)) { if (neg) mask_unset(mask, LEVELNUM(i)); else mask_set(mask, LEVELNUM(i)); break; } } if (i == level_bucket->numitems) malloc_strcat_word_c(rejects, space, str, DWORD_NO, &cluep); } } str = ptr; } str = rest; } if (rejects && *rejects) return -1; return 0; }
int main(int argc,char* argv[]) { int w, h; int board[12][12];//表示、非表示のフラグ格納用配列 int mask[12][12]; int mine_sum = 10; IplImage *img,*img_out; int point[2]; bool clear_flag = false; bool false_flag = false; if((img = cvCreateImage(cvSize(WIDTH, HEIGHT), IPL_DEPTH_32F, 3)) == NULL) { printf("画像リソースを確保できません。\n"); return -1; } w = WIDTH, h = HEIGHT; img_out = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3); // 整数型画像リソース確保 cvNamedWindow("mine_s"); cvSetMouseCallback("mine_s", on_mouse, point); cvSet(img, cvScalar(0,0,0), 0); // 画像リソース初期化 img_set(img,h,w); //imgに色を付ける map_set(board); //board初期化 map_set(mask); //mask初期化 mine_set(mask,mine_sum);//地雷セット mask_set(mask); while(1){ //左クリックされた時の処理 if(get_Lpoint().x != -1 && get_Lpoint().y != -1){ L_button_reverse(get_Lpoint().x,get_Lpoint().y,board,mask); character(img,mask,board); //地雷を踏んだか調べる if(mask[get_Lpoint().y/40][get_Lpoint().x/40-1] == -2){ false_flag = true; } set_Lpoint(-1,-1); } //GameClearCheck clear_flag = clear_check(board,mask,mine_sum); if(get_Rpoint().x != -1 && get_Rpoint().y != -1){ R_button_reverse(get_Rpoint().x,get_Rpoint().y,board); exclamation_draw(img,board); } if(clear_flag){ printf("GameClear\n"); //break; } if(false_flag){ printf("GameOver\n"); //break; } cvConvertImage(img, img_out); // 浮動小数点数型から整数型画像に変換 cvShowImage("mine_s", img_out); // 表示 if(cvWaitKey(33) == 27) break; // ESCを押した時終了 } // ウィンドウ・キャプチャ・画像リソースの解放 cvDestroyAllWindows(); cvReleaseImage( &img_out); cvReleaseImage( &img); return 0; }