// this should probably go into some common util stuff // or in scc_fd dunno scc_data_t* scc_data_load(char* path) { scc_data_t* data; scc_fd_t* fd; int len; fd = new_scc_fd(path,O_RDONLY,0); if(!fd) { scc_log(LOG_ERR,"Failed to open %s.\n",path); return NULL; } // get file size scc_fd_seek(fd,0,SEEK_END); len = scc_fd_pos(fd); scc_fd_seek(fd,0,SEEK_SET); data = malloc(sizeof(scc_data_t) + len); data->size = len; if(scc_fd_read(fd,data->data,len) != len) { scc_log(LOG_ERR,"Failed to load %s\n",path); free(data); scc_fd_close(fd); return NULL; } scc_fd_close(fd); return data; }
int glob(const char *pattern, int flags, int (*errfunc)(const char *epath, int eerrno), glob_t *pglob) { HANDLE searchhndl; WIN32_FIND_DATA found_file; if(errfunc) scc_log(LOG_ERR,"glob():ERROR: Sorry, errfunc not supported " "by this implementation\n"); if(flags) scc_log(LOG_ERR,"glob():ERROR:Sorry, no flags supported " "by this implementation\n"); //scc_log(LOG_DBG,"PATTERN \"%s\"\n",pattern); pglob->gl_pathc = 0; searchhndl = FindFirstFile( pattern,&found_file); if(searchhndl == INVALID_HANDLE_VALUE) { if(GetLastError() == ERROR_FILE_NOT_FOUND) { pglob->gl_pathc = 0; //scc_log(LOG_DBG,"could not find a file matching your search criteria\n"); return 1; } else { //scc_log(LOG_DBG,"glob():ERROR:FindFirstFile: %i\n",GetLastError()); return 1; } } pglob->gl_pathv = malloc(sizeof(char*)); pglob->gl_pathv[0] = strdup(found_file.cFileName); pglob->gl_pathc++; while(1) { if(!FindNextFile(searchhndl,&found_file)) { if(GetLastError()==ERROR_NO_MORE_FILES) { //scc_log(LOG_DBG,"glob(): no more files found\n"); break; } else { //scc_log(LOG_DBG,"glob():ERROR:FindNextFile:%i\n",GetLastError()); return 1; } } else { //scc_log(LOG_DBG,"glob: found file %s\n",found_file.cFileName); pglob->gl_pathc++; pglob->gl_pathv = realloc(pglob->gl_pathv,pglob->gl_pathc * sizeof(char*)); pglob->gl_pathv[pglob->gl_pathc-1] = strdup(found_file.cFileName); } } FindClose(searchhndl); return 0; }
scc_loop_t* scc_loop_pop(void) { scc_loop_t* l; if(!loop_stack) { scc_log(LOG_ERR,"Can't pop empty loop stack.\n"); return NULL; } l = loop_stack; loop_stack = l->next; l->next = NULL; return l; }
void scc_loop_push(int type, char* sym) { scc_loop_t* l; if(sym && scc_loop_get(SCC_BRANCH_BREAK,sym)) { scc_log(LOG_ERR,"Warning: there is already a loop named %s in the loop stack.\n", sym); } l = calloc(1,sizeof(scc_loop_t)); l->id = (loop_stack ? loop_stack->id : 0) + 1; l->type = type; l->sym = sym; l->next = loop_stack; loop_stack = l; }
static scc_code_t* scc_code_push_res(uint8_t op,scc_symbol_t* res) { scc_code_t* c,*d; // Address is alredy assigned if(res->addr >= 0) return scc_code_push_val(op,res->addr); if(!res->rid) { scc_log(LOG_ERR,"Resource %s has no assigned rid!!!!\n",res->sym); return NULL; } // no addr, so code the op and addr separatly c = scc_code_new(1); c->data[0] = op; d = scc_code_new(2); SCC_SET_16LE(d->data,0,res->rid); d->fix = SCC_FIX_RES + res->type; c->next = d; return c; }
static void scc_loop_fix_code(scc_code_t* c,int br, int cont) { scc_loop_t* l = scc_loop_pop(); int pos = 0; for( ; c ; c = c->next) { pos += c->len; if(c->fix != SCC_FIX_BRANCH) continue; if(c->data[1] != l->id) continue; if(c->data[2] == SCC_BRANCH_BREAK) { SCC_SET_S16LE(c->data,1,br - pos); } else if(cont >= 0 && c->data[2] == SCC_BRANCH_CONTINUE) { SCC_SET_S16LE(c->data,1,cont - pos); } else { SCC_SET_S16LE(c->data,1,pos); } c->fix = SCC_FIX_NONE; scc_log(LOG_DBG,"Branch fixed to 0x%hx\n",SCC_GET_16LE(c->data,1)); } free(l); }
int main(int argc,char** argv) { scc_cl_arg_t* files; scc_smf_t* smf; files = scc_param_parse_argv(scc_parse_params,argc-1,&argv[1]); if(!files) scc_print_help(&midi_help,1); smf = scc_smf_parse_file(files->val); if(!smf) return 1; if(dump) { scc_smf_dump(smf); return 0; } if(merge && merge[0] > 1) { int t; for(t = 2 ; t < merge[0]+1 ; t++) scc_smf_merge_track(smf,merge[1],merge[t]); } if(strip_track >= 0) { if(strip_track >= smf->num_track) { scc_log(LOG_ERR,"Track %d doesn't exist, there are only %d tracks.\n", strip_track,smf->num_track); return 1; } scc_smf_remove_track(smf,strip_track); } if(set_type >= 0) smf->type = set_type; return !scc_smf_write_file(smf,files->next->val); }
void scvm_actor_walk_step(scvm_actor_t* a,scvm_room_t* room) { int dstDir,step,len; if(a->walking == SCVM_ACTOR_WALKING_STOPPED) return; if(a->x == a->walk_to_x && a->y == a->walk_to_y) { a->walking = SCVM_ACTOR_WALKING_STOPPED; a->box = a->walk_to_box; if(a->walk_to_dir >= 0 && a->walk_to_dir != a->direction) { // TODO: turn to the right direction a->direction = a->walk_to_dir; } scvm_actor_animate(a,a->stand_frame); return; } if(a->walking == SCVM_ACTOR_WALKING_TO_DST && a->x == a->dstX && a->y == a->dstY) { a->box = a->dst_box; a->walking = SCVM_ACTOR_WALKING_FIND_DST; } if(a->walking == SCVM_ACTOR_WALKING_INIT) { if(!(a->flags & SCVM_ACTOR_IGNORE_BOXES)) { scc_box_t* box = scc_boxes_adjust_point(room->box, a->walk_to_x, a->walk_to_y, &a->walk_to_x, &a->walk_to_y); a->walk_to_box = box->id; } else a->walk_to_box = a->box; a->walking = SCVM_ACTOR_WALKING_FIND_DST; } if(a->walking == SCVM_ACTOR_WALKING_FIND_DST) { if((a->flags & SCVM_ACTOR_IGNORE_BOXES) || a->box == a->walk_to_box) { a->dstX = a->walk_to_x; a->dstY = a->walk_to_y; } else { // Find the next box a->dst_box = room->boxm[a->box*room->num_box+a->walk_to_box]; if(a->dst_box >= room->num_box) { scc_log(LOG_ERR,"Bad destination box: %d from %d.\n", a->dst_box,a->box); a->walking = SCVM_ACTOR_WALKING_STOPPED; scvm_actor_animate(a,a->stand_frame); return; } // Adjust the point inside the box scc_box_adjust_point(&room->box[a->dst_box],a->x,a->y, &a->dstX,&a->dstY); } // Turn if needed dstDir = get_direction_to(a->x,a->y,a->dstX,a->dstY); if(dstDir != a->direction) { // TODO: turn to the right direction a->direction = dstDir; } // Setup the walking variables a->walk_dx = abs(a->dstX - a->x); a->walk_dy = abs(a->dstY - a->y); a->walk_err = 0; a->walking = SCVM_ACTOR_WALKING_TO_DST; scvm_actor_animate(a,a->walk_frame); return; } if(a->walk_dy >= a->walk_dx) { // north/south step = (a->dstY > a->y) ? 1 : -1; for(len = 0 ; len < a->walk_speed_y && (a->x != a->dstX || a->y != a->dstY) ; len++) { a->y += step; a->walk_err += a->walk_dx; if(a->walk_err<<1 >= a->walk_dy) { a->walk_err -= a->walk_dy; a->x += (a->dstX >= a->x) ? 1 : -1; } } } else { // east/west step = (a->dstX > a->x) ? 1 : -1; for(len = 0 ; len < a->walk_speed_x && (a->x != a->dstX || a->y != a->dstY) ; len++) { a->x += step; a->walk_err += a->walk_dy; if(a->walk_err<<1 >= a->walk_dx) { a->walk_err -= a->walk_dx; a->y += (a->dstY >= a->y) ? 1 : -1; } } } }