Ejemplo n.º 1
0
static void *delete_internal(rxt_node *n, rxt_node *sibling)
{
    rxt_node *parent = n->parent;
    void *v = n->value;
    
    /* TODO ascii art */
    if (sibling->color) {
        parent->value = sibling;
        parent->left = NULL;
        parent->right = NULL;
        parent->color = 2;
        parent->pos = 0;
        reset_key(n->key, sibling->key, parent);
    } else {
        parent->left = sibling->left;
        parent->right = sibling->right;
        parent->pos = sibling->pos;
        sibling->left->parent = parent;
        sibling->right->parent = parent;
        reset_key(n->key, sibling->key, parent);
        free(sibling);
    }
    
    free(n);
    return v;
}
Ejemplo n.º 2
0
void change_disk(void) {
  path_t path;

  if (swaplist.fs == NULL) {
    /* No swaplist active, try using AUTOSWAP.LST */
    /* change_disk is called from the IEC idle loop, so ops_scratch is free */
    ustrcpy_P(ops_scratch, autoswap_lst_name);
    path.dir  = partition[current_part].current_dir;
    path.part = current_part;
    if (key_pressed(KEY_PREV))
      set_changelist_internal(&path, ops_scratch, 1);
    else
      set_changelist_internal(&path, ops_scratch, 0);

    if (swaplist.fs == NULL) {
      /* No swap list found, create one if key was "home" */
      if (key_pressed(KEY_HOME)) {
        uint8_t swapname[16]; // FIXME: magic constant

        ustrcpy_P(swapname, autoswap_gen_name);

        if (create_changelist(&path, swapname)) {
          set_changelist_internal(&path, swapname, 0);
          globalflags |= AUTOSWAP_ACTIVE;
        }
      }

      /* reset error and exit */
      set_error(ERROR_OK);
      reset_key(0xff); // <- lazy
      return;
    } else {
      /* Autoswaplist found, mark it as active                */
      /* and exit because the first image is already mounted. */
      globalflags |= AUTOSWAP_ACTIVE;
      reset_key(0xff); // <- lazy
      return;
    }
  }

  /* Mount the next image in the list */
  if (key_pressed(KEY_NEXT)) {
    linenum++;
    reset_key(KEY_NEXT);
    if (mount_line())
      confirm_blink(BLINK_FORWARD);
  } else if (key_pressed(KEY_PREV)) {
    linenum--;
    reset_key(KEY_PREV);
    if (mount_line())
      confirm_blink(BLINK_BACKWARD);
  } else if (key_pressed(KEY_HOME)) {
    linenum = 0;
    reset_key(KEY_HOME);
    if (mount_line())
      confirm_blink(BLINK_HOME);
  }
}
Ejemplo n.º 3
0
void Client::on_input_event(const InputData& input) {
    if (!are_options_visible()) {
        switch (input.data_type) {
            case InputData::InputDataTypeKeyDown:
                set_key(MappedKey::DeviceKeyboard, input.keycode);
                /* escape fallback */
                if (input.key_type == InputData::InputKeyTypeEscape) {
                    if (!input.key_repeat) {
                        show_options_menu();
                    }
                }
                break;

            case InputData::InputDataTypeKeyUp:
                reset_key(MappedKey::DeviceKeyboard, input.keycode);
                break;

            case InputData::InputDataTypeJoyButtonDown:
                set_key(MappedKey::DeviceJoyButton, input.param1);
                break;

            case InputData::InputDataTypeJoyButtonUp:
                reset_key(MappedKey::DeviceJoyButton, input.param1);
                break;

            case InputData::InputDataTypeJoyMotion:
            {
                joyaxis_t axis = static_cast<joyaxis_t>(input.param1);
                if (me) {
                    if (!get_stack_count()) {
                        me->state.client_server_state.jaxis = axis;
                    } else {
                        me->state.client_server_state.jaxis = 0;
                    }
                }
                break;
            }

            default:
                break;
        }
    }
}
Ejemplo n.º 4
0
gn_error db_phone_store(void)
{
    char *begin = strdup(BEGIN_PHONE);
    char *end = strdup(END_PHONE);
    int fd;
    char buffer[256];
    int len;

    snprintf(buffer, sizeof(buffer), "%s.encode", PHONE_FILENAME_BUFFER);
    LOGMSG(LOG_LEVEL_INFO, "Will save phonebook to file %s\n", buffer);
    fd = open(buffer, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd < 0) {
        LOGMSG(LOG_LEVEL_CRIT, "Could not open file %s for saving phonebook\n", buffer);
        goto out;
    }
    //Reset key
    reset_key();
    encode(begin, strlen(BEGIN_PHONE));
    if (safe_write(fd, begin, strlen(BEGIN_PHONE))) {
        LOGMSG(LOG_LEVEL_CRIT, "Write fail. Could not save phonebook\n");
        goto out;
    }
    phone_entry_t* entry = G_phoneBook.head;
    while(entry) {
        if (entry->next) {
            len = snprintf(buffer, sizeof(buffer), "{\"name\": \"%s\", \"phone\": \"%s\"},\n", 
                    entry->name, entry->phoneNo);
        } else {
            len = snprintf(buffer, sizeof(buffer), "{\"name\": \"%s\", \"phone\": \"%s\"}\n", 
                    entry->name, entry->phoneNo);
        }
        encode(buffer, len);
        if (safe_write(fd, buffer, len)) {
            LOGMSG(LOG_LEVEL_CRIT, "Write fail. Could not save phonebook\n");
            goto out;
        }
        entry = entry->next;
    }
    encode(end, strlen(END_PHONE));
    if (safe_write(fd, end, strlen(END_PHONE))) {
        LOGMSG(LOG_LEVEL_CRIT, "Write fail. Could not save phonebook\n");
        goto out;
    }
out:
    if (fd >= 0) {
        close(fd);
    }
    free(begin);
    free(end);
    return GN_ERR_NONE;
}
Ejemplo n.º 5
0
void Client::reset_key(MappedKey::Device dev, int param) {
    reset_key(dev, param, binding.left, PlayerKeyStateLeft);
    reset_key(dev, param, binding.right, PlayerKeyStateRight);
    reset_key(dev, param, binding.up, PlayerKeyStateUp);
    reset_key(dev, param, binding.down, PlayerKeyStateDown);
    reset_key(dev, param, binding.jump, PlayerKeyStateJump);
    reset_key(dev, param, binding.fire, PlayerKeyStateFire);
    reset_key(dev, param, binding.drop1, PlayerKeyStateDrop1);
    reset_key(dev, param, binding.drop2, PlayerKeyStateDrop2);
    reset_key(dev, param, binding.drop3, PlayerKeyStateDrop3);

    if (binding.stats.device == dev && binding.stats.param == param) {
        if (!get_stack_count()) {
            if (tournament) {
                tournament->show_stats(false);
            }
        }
    }
}
Ejemplo n.º 6
0
static void reset_key(char *key, char *newkey, rxt_node *n)
{
    // This should only be propagated up inner nodes.
    // Right now the algorithm guarantees this, but it is unchecked.

    if (key == n->key) {
        n->key = newkey;
        if (n->left && n->right)
            n->pos = count_common_bits(n->left->key, n->right->key,
                                   rdx_min(n->left->pos, n->right->pos));

        if (n->parent)
            reset_key(key, newkey, n->parent);
    }
}
Ejemplo n.º 7
0
void ieee_mainloop(void) {
  int16_t cmd = 0;

  set_error(ERROR_DOSVERSION);

  ieee_data.bus_state = BUS_IDLE;
  ieee_data.device_state = DEVICE_IDLE;
  for(;;) {
    switch(ieee_data.bus_state) {
      case BUS_SLEEP:                               /* BUS_SLEEP */
        set_atn_irq(0);
        ieee_bus_idle();
        set_error(ERROR_OK);
        set_busy_led(0);
        uart_puts_P(PSTR("ieee.c/sleep ")); set_dirty_led(1);

        /* Wait until the sleep key is used again */
        while (!key_pressed(KEY_SLEEP))
          system_sleep();
        reset_key(KEY_SLEEP);

        set_atn_irq(1);
        update_leds();

        ieee_data.bus_state = BUS_IDLE;
        break;

      case BUS_IDLE:                                /* BUS_IDLE */
        ieee_bus_idle();
        while(IEEE_ATN) {   ;               /* wait for ATN */
          if (key_pressed(KEY_NEXT | KEY_PREV | KEY_HOME)) {
            change_disk();
          } else if (key_pressed(KEY_SLEEP)) {
            reset_key(KEY_SLEEP);
            ieee_data.bus_state = BUS_SLEEP;
            break;
          } else if (display_found && key_pressed(KEY_DISPLAY)) {
            display_service();
            reset_key(KEY_DISPLAY);
          }
          system_sleep();
      }

      if (ieee_data.bus_state != BUS_SLEEP)
        ieee_data.bus_state = BUS_FOUNDATN;
      break;

      case BUS_FOUNDATN:                            /* BUS_FOUNDATN */
        ieee_data.bus_state = BUS_ATNPROCESS;
        cmd = ieee_getc();
      break;

      case BUS_ATNPROCESS:                          /* BUS_ATNPROCESS */
        if(cmd < 0) {
          uart_putc('c');
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else cmd &= 0xFF;
        uart_puts_p("ATN "); uart_puthex(cmd);
        uart_putcrlf();

        if (cmd == 0x3f) {                                  /* UNLISTEN */
          if(ieee_data.device_state == DEVICE_LISTEN) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNLISTEN\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == 0x5f) {                           /* UNTALK */
          if(ieee_data.device_state == DEVICE_TALK) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNTALK\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x40 + device_address)) {        /* TALK */
          uart_puts_p("TALK ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.device_state = DEVICE_TALK;
          /* disk drives never talk immediatly after TALK, so stay idle
             and wait for a secondary address given by 0x60-0x6f DATA */
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x20 + device_address)) {        /* LISTEN */
          ieee_data.device_state = DEVICE_LISTEN;
          uart_puts_p("LISTEN ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0x60) {                  /* DATA */
          /* 8250LP sends data while ATN is still active, so wait
             for bus controller to release ATN or we will misinterpret
             data as a command */
          while(!IEEE_ATN);
          if(ieee_data.device_state == DEVICE_LISTEN) {
            cmd = ieee_listen_handler(cmd);
            cmd_handler();
            break;
          } else if (ieee_data.device_state == DEVICE_TALK) {
            ieee_data.secondary_address = cmd & 0x0f;
            uart_puts_p("DATA T ");
            uart_puthex(ieee_data.secondary_address);
            uart_putcrlf();
            if(ieee_talk_handler() == TIMEOUT_ABORT) {
              ieee_data.device_state = DEVICE_IDLE;
            }
            ieee_data.bus_state = BUS_IDLE;
            break;
          } else {
            ieee_data.bus_state = BUS_IDLE;
            break;
          }
        } else if (ieee_data.device_state == DEVICE_IDLE) {
          ieee_data.bus_state = BUS_IDLE;
          break;
          /* ----- if we reach this, we're LISTENer or TALKer ----- */
        } else if ((cmd & 0xf0) == 0xe0) {                  /* CLOSE */
          ieee_data.secondary_address = cmd & 0x0f;
          uart_puts_p("CLOSE ");
          uart_puthex(ieee_data.secondary_address);
          uart_putcrlf();
          /* Close all buffers if sec. 15 is closed */
          if(ieee_data.secondary_address == 15) {
            free_multiple_buffers(FMB_USER_CLEAN);
          } else {
            /* Close a single buffer */
            buffer_t *buf;
            buf = find_buffer (ieee_data.secondary_address);
            if (buf != NULL) {
              buf->cleanup(buf);
              free_buffer(buf);
            }
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0xf0) {                  /* OPEN */
          cmd = ieee_listen_handler(cmd);
          cmd_handler();
          break;
        } else {
          /* Command for other device or unknown command */
          ieee_data.bus_state = BUS_IDLE;
        }
      break;
    }   /* switch   */
  }     /* for()    */
}
Ejemplo n.º 8
0
void* rxt_delete(char *key, rxt_node *root)
{
    rxt_node *parent, *grandparent;
    rxt_node *n = get_internal(key, root);
    void *v;
    char *newkey = NULL;
    if (!n) return NULL; // nonexistent

    v = n->value;

    // remove both the node and the parent inner node
    // XXX TODO FIXME Still somewhat broken. Figure out.
    parent = n->parent;
    grandparent = parent->parent;

    if (!grandparent) {
        if (parent->left == n) {
            return delete_internal(n, parent->right);
        } else if (parent->right == n) {
            return delete_internal(n, parent->left);
        } else if (parent->value == n) {
            parent->value = NULL;
            parent->color = 0;
            parent->pos = 0;
        } else
            printf("something very wrong when removing w/o gp!\n");

        free(n);
        return v;
    }

    // properly move around pointers and shit
    // TODO ascii art
    if (grandparent->left == n->parent) {
        newkey = grandparent->right->key; // not sure if this is correct
        if (parent->left == n) {
            grandparent->left = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->left = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->left\n");
    } else if (grandparent->right == n->parent) {
        newkey = grandparent->left->key;
        if (parent->left == n ) {
            grandparent->right = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->right = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->right\n");
    } else
        printf("something very wrong: grandparent does not possess child\n");

    reset_key(n->key, newkey, grandparent);
    parent->left = NULL;
    parent->right = NULL;
    free(parent);
    free(n); // we don't dynamically allocate node

    return v;
}
Ejemplo n.º 9
0
int main(void) {
  /* Early system initialisation */
  board_init();
  system_init_early();
  leds_init();

  set_busy_led(1);
  set_dirty_led(0);

  /* Due to an erratum in the LPC17xx chips anything that may change */
  /* peripheral clock scalers must come before system_init_late()    */
  uart_init();
#ifndef SPI_LATE_INIT
  spi_init(SPI_SPEED_SLOW);
#endif
  timer_init();
  bus_interface_init();
  i2c_init();

  /* Second part of system initialisation, switches to full speed on ARM */
  system_init_late();
  enable_interrupts();

  /* Internal-only initialisation, called here because it's faster */
  buffers_init();
  buttons_init();

  /* Anything that does something which needs the system clock */
  /* should be placed after system_init_late() */
  bus_init();    // needs delay
  rtc_init();    // accesses I2C
  disk_init();   // accesses card
  read_configuration();

  fatops_init(0);
  change_init();

  uart_puts_P(PSTR("\r\nsd2iec " VERSION " #"));
  uart_puthex(device_address);
  uart_putcrlf();

#ifdef CONFIG_REMOTE_DISPLAY
  /* at this point all buffers should be free, */
  /* so just use the data area of the first to build the string */
  uint8_t *strbuf = buffers[0].data;
  ustrcpy_P(strbuf, versionstr);
  ustrcpy_P(strbuf+ustrlen(strbuf), longverstr);
  if (display_init(ustrlen(strbuf), strbuf)) {
    display_address(device_address);
    display_current_part(0);
  }
#endif

  set_busy_led(0);

#if defined(HAVE_SD) && BUTTON_PREV != 0
  /* card switch diagnostic aid - hold down PREV button to use */
  if (!(buttons_read() & BUTTON_PREV)) {
    while (buttons_read() & BUTTON_NEXT) {
      set_dirty_led(sdcard_detect());
# ifndef SINGLE_LED
      set_busy_led(sdcard_wp());
# endif
    }
    reset_key(0xff);
  }
#endif

  bus_mainloop();

  while (1);
}