/* * Common routine to change the equipment address of a peripheral. Some * devices (e.g. TT, PTR etc) cannot have their equipment address changed. */ t_stat set_equipment(UNIT *uptr, int32 val, CONST char *cptr, void *desc) { DEVICE *dptr; IO_DEVICE *iod; t_value v; t_stat r; if (cptr == NULL) return SCPE_ARG; v = get_uint(cptr, DEV_RDX, 15, &r); if (r != SCPE_OK) return r; if (v == 0) return SCPE_ARG; /* * Check to see if any other, non-disabled device is already using this * address. */ if ((dptr = find_dev_from_unit(uptr)) != NULL) { if (checkDuplicate(dptr, v)) return sim_messagef(SCPE_ARG, "Equipment address already in use\n"); iod = (IO_DEVICE *)dptr->ctxt; iod->iod_equip = v; iod->iod_interrupt = 1 << v; return SCPE_OK; } return SCPE_NXDEV; }
/* * Check for a duplicate address when a device is reset. If a duplicate is * found, the device being reset is disabled. */ t_stat checkReset(DEVICE *dptr, uint8 equipment) { if (checkDuplicate(dptr, equipment)) { dptr->flags |= DEV_DIS; return sim_messagef(SCPE_ARG, "Equipment address already in use\n"); } return SCPE_OK; }
/*implements A* algorithm*/ tree astar(int x, int y, int d, int heuristic){ char a = 'X';//X simbolize that no action was taken to get there tree t, t1, t2; char **mat1, **mat2; int i, j; int level; double f; queue_vector aux; int k; //copy the starting matrix mat1 = newMatrix(); for(i = 0; i < n; i++){ for(j = 0; j < m; j++) mat1[i][j] = w[i][j]; } t1 = insertTree(NULL, d, x, y, mat1, a, 0); t = t1; //compute the f value according to the heuristic f = computeHeuristic(x, y, 0, heuristic); insertQueue(t1, f); while(n_queue > 0){ //remove the first element of the queue removeQueue(&aux.t, &aux.f); t1 = aux.t; d = t1 -> dirt; mat1 = t1 -> mat; a = t1 -> action; x = t1 -> x; y = t1 -> y; level = t1 -> level; //increments the number of nodes expanded expanded++; //adds into the queue if(y != 0 && mat1[y-1][x] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y-1][x]; mat2[y-1][x] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x, y-1), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x, y-1); t2 = insertTree(t1, d-1, x, y-1, mat2, 'n', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x, y-1, mat2, 'N', level + 1); t1 -> N = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(y != n - 1 && mat1[y+1][x] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y+1][x]; mat2[y+1][x] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x, y+1), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x, y+1); t2 = insertTree(t1, d-1, x, y+1, mat2, 's', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x, y+1, mat2, 'S', level + 1); t1 -> S = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(x != 0 && mat1[y][x-1] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y][x-1]; mat2[y][x-1] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x - 1, y), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x-1, y); t2 = insertTree(t1, d-1, x-1, y, mat2, 'w', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x-1, y, mat2, 'W', level + 1); t1 -> W = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(x != m - 1 && mat1[y][x+1] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y][x+1]; mat2[y][x+1] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x + 1, y), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x+1, y); t2 = insertTree(t1, d-1, x+1, y, mat2, 'e', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x+1, y, mat2, 'E', level + 1); t1 -> E = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } orderQueue(); } return NULL; }