//get pin map from the xml nodes static int get_pin_map(node_t *node,u8 *pins,int maxpins) { node_t *pin; char *num,*func; u8 pinnum,pinfunc; //clear pins array memset(pins,P_ERROR,maxpins); //get first pin node pin = get_child("pin",node); while(pin) { //get pin number and function attributes num = find_attrib(pin,"number"); func = find_attrib(pin,"function"); //get and verify the pin number pinnum = (u8)atoi(num); if(pinnum >= maxpins) { log_printf("get_pin_map: pinnum exceeds maxpins\n"); continue; } //get and verify the pin function pinfunc = get_pin_func(func); if(pinfunc != P_ERROR) pins[pinnum] = pinfunc; //get node sibling for continued processing pin = get_sibling("pin",pin); } return(0); }
static int hasbattery(node_t *node) { char *tmp = find_attrib(node,"battery"); if(tmp && strcmp(tmp,"1") == 0) return(1); return(0); }
//process chip nodes static int process_chip(int mapperid,char *board,int mapper,node_t *node) { char *chip; u8 pins[64]; if((chip = find_attrib(node,"type")) == 0) return(mapperid); //SxROM boards, process mmc1 type if(mapperid == B_NINTENDO_SxROM) { if(strncmp(chip,"MMC1A",5) == 0) mapperid = B_NINTENDO_SxROM_MMC1A; else if(strncmp(chip,"MMC1B",5) == 0) mapperid = B_NINTENDO_SxROM_MMC1B; else if(strncmp(chip,"MMC1C",5) == 0) mapperid = B_NINTENDO_SxROM_MMC1C; log_printf("process_chip: mmc1 chip type: %s\n",chip); } //vrc2 boards, find wiring configuration if(mapperid == B_KONAMI_VRC2) { if(strncmp(chip,"VRC2",4) == 0 && get_pin_map(node,pins,64) == 0) { if(pins[3] == P_PRG_A0 && pins[4] == P_PRG_A1) { if(pins[21] == P_NC) { mapperid = B_KONAMI_VRC2A; log_printf("process_chip: vrc2a detected.\n"); } else { mapperid = B_KONAMI_VRC4B; log_printf("process_chip: vrc2c detected, using vrc4b.\n"); } } else if(pins[3] == P_PRG_A1 && pins[4] == P_PRG_A0) { mapperid = B_KONAMI_VRC2B; log_printf("process_chip: vrc2b detected.\n"); } else log_printf("process_chip: unknown vrc2 pin configuration (pin3 = %d, pin4 = %d)\n",pins[3],pins[4]); } } //leave these alone! if(mapper == 93) { mapperid = B_SUNSOFT_2; log_printf("process_chip: sunsoft-3R board. using sunsoft-2 mapper.\n"); } //return new mapperid return(mapperid); }
static node_t *find_cart(u32 crc32) { node_t *gamenode,*cartnode; char *str; u32 n; for(gamenode = cartxml->root->child; gamenode; gamenode = gamenode->next) { if(strcmp(gamenode->name,"game") != 0) continue; for(cartnode = gamenode->child; cartnode; cartnode = cartnode->next) { if(strcmp(cartnode->name,"cartridge") != 0) continue; if((str = find_attrib(cartnode,"crc")) != 0) { n = hexstr2int(str); if(n == crc32) return(cartnode); } } } return(0); }
int cartdb_find(cart_t *cart) { node_t *cartnode,*boardnode,*node; u32 crc32,wramsize,vramsize,battery; char *str,*str2,*tmp; if(cartxml == 0) return(1); //calculate crc32 of entire image crc32 = crc32_block(cart->prg.data,cart->prg.size,0); crc32 = crc32_block(cart->chr.data,cart->chr.size,crc32); //initialize the size and battery vars wramsize = vramsize = 0; battery = 0; //try to find cart node with same crc32 cartnode = find_cart(crc32); if(cartnode) { //copy game title if((str = find_attrib(cartnode->parent,"name"))) strcpy(cart->title,str); //see if board node exists if((boardnode = get_child("board",cartnode))) { //get unif board name and ines mapper number str = find_attrib(boardnode,"type"); str2 = find_attrib(boardnode,"mapper"); //set mapperid with information discovered cart->mapperid = determine_mapperid(cart,str,str2,boardnode); //find the vram size node = get_child("vram",boardnode); while(node) { tmp = find_attrib(node,"size"); if(tmp) { battery |= hasbattery(node) << 1; vramsize += sizestr2int(tmp); } node = get_sibling("vram",node); } //find the wram size and battery status node = get_child("wram",boardnode); while(node) { tmp = find_attrib(node,"size"); if(tmp) { battery |= hasbattery(node); wramsize += sizestr2int(tmp); } node = get_sibling("wram",node); } //debug messages if(wramsize) { cart_setwramsize(cart,wramsize / 1024); if(battery & 1) cart->battery |= 1; } if(vramsize) { cart_setvramsize(cart,vramsize / 1024); if(battery & 2) cart->battery |= 2; } return(0); } } log_printf("cartdb_find: cart not found in database.\n"); return(1); }
bool do_test(const struct test *tests, unsigned num_tests) { bool pass = true; unsigned i; for (i = 0; i < num_tests; i++) { GLint vert = piglit_compile_shader_text(GL_VERTEX_SHADER, tests[i].code); GLint prog = piglit_link_simple_program(vert, 0); GLint num_attr; unsigned visited_count[64]; unsigned j; bool shader_dumped = false; memset(visited_count, 0, sizeof(visited_count)); /* From page 93 (page 109 of the PDF) says: * * "An attribute variable (either conventional or generic) * is considered active if it is determined by the * compiler and linker that the attribute may be accessed * when the shader is executed. Attribute variables that * are declared in a vertex shader but never used will not * count against the limit. In cases where the compiler * and linker cannot make a conclusive determination, an * attribute will be considered active." * * Compare the set of active attributes against the list of * expected active attributes. */ piglit_GetProgramiv(prog, GL_ACTIVE_ATTRIBUTES, &num_attr); for (j = 0; j < num_attr; j++) { const struct attribute *attr; char name_buf[256]; int attr_idx; GLsizei name_len; GLint size; GLenum type; glGetActiveAttrib(prog, j, sizeof(name_buf), &name_len, &size, &type, name_buf); attr_idx = find_attrib(tests[i].attributes, name_buf); /* If the named attribute is not in the list for the * test, then it must not be active. */ if (attr_idx < 0) { DUMP_SHADER(tests[i].code); fprintf(stderr, "Attribute `%s' should not be active " "but is.\n", name_buf); pass = false; continue; } attr = &tests[i].attributes[attr_idx]; if (visited_count[attr_idx] != 0) { DUMP_SHADER(tests[i].code); fprintf(stderr, "Attribute `%s' listed multiple times " "in active list.\n", name_buf); pass = false; } else if (attr->size != size) { DUMP_SHADER(tests[i].code); fprintf(stderr, "Attribute `%s' should have size %d, " "but had size %d.\n", name_buf, attr->size, size); pass = false; } else if (attr->type != type) { DUMP_SHADER(tests[i].code); fprintf(stderr, "Attribute `%s' should have type " "0x%04x, but had type 0x%04x.\n", name_buf, attr->type, type); pass = false; } visited_count[attr_idx]++; } for (j = 0; tests[i].attributes[j].name != NULL; j++) { if (tests[i].attributes[j].must_be_active && visited_count[j] == 0) { DUMP_SHADER(tests[i].code); fprintf(stderr, "Attribute `%s' should have been " "active but wasn't.\n", tests[i].attributes[j].name); pass = false; } } } return pass; }