Example #1
0
// This routine is called by usbFunctionWrite every time the keyboard LEDs
// toggle - basically we count 4 toggles and then start regenerating
void caps_toggle() {
    if(capsState == CAPS_COUNTING) {    
        if(capsCount++ < 4)
            return;
        
        capsCount = 0;
        capsState = CAPS_MEASURING;

        // Type a message to the PC that we're regenerating the password
        memcpy_P(messageBuffer, measuring_message, sizeof(measuring_message));
        messagePtr = 0;
        messageState = STATE_SEND;
    } else {
        messageBuffer[capsCount++] = generate_character();
        
        if(capsCount >= PASS_LENGTH) { // enough characters generated
#if SEND_ENTER
            messageBuffer[capsCount++] = '\n';
#endif
            messageBuffer[capsCount] = '\0';
            
            // Store password to EEPROM - might lose the USB connection, but so what
            eeprom_write_block(messageBuffer, stored_password, sizeof(messageBuffer));
            
            // Type a message to the PC that new password has been generated
            memcpy_P(messageBuffer, finish_message, sizeof(finish_message));
            messagePtr = 0;
            messageState = STATE_SEND;
            
            capsCount = 0;
            capsState = CAPS_COUNTING;
        }
    }    
}
Example #2
0
int
main(int argc, char *argv[])
{
    FILE *out = stdout;
    struct options *options = options_alloc(argc, argv);
    
    if (options->error || options->help) {
        options_print_usage(options);
        return options->error? EXIT_FAILURE : EXIT_SUCCESS;
    }
    
    if (action_game == options->action) {
        play_game(options->rnd);
    } else if (action_tui == options->action) {
        run_tui();
    } else {
        fprintf(out, "Fiends and Fortune\n");
        switch (options->action) {
            case action_character:
                generate_character(options->rnd, out, options->character_method);
                break;
            case action_check:
                check(out, options->check_constant);
                break;
            case action_dungeon:
                if (options->dungeon_type_small) {
                    generate_sample_dungeon(options->rnd, out);
                } else {
                    generate_random_dungeon(options->rnd, out);
                }
                break;
            case action_each:
                generate_each_treasure(options->rnd, out);
                break;
            case action_magic:
                generate_magic_items(options->rnd, out, options->magic_count);
                break;
            case action_map:
                generate_map(options->rnd, out);
                break;
            case action_table:
                generate_treasure_type_table(out);
                break;
            case action_treasure:
                generate_treasure_type(options->rnd, out, options->treasure_type);
                break;
            default:
                fprintf(stderr, "%s: unrecognized option\n", options->command_name);
                break;
        }
        fprintf(out, "\n");
    }
    
    options_free(options);
    alloc_count_is_zero_or_die();
    return EXIT_SUCCESS;
}
Example #3
0
static void
check(FILE *out, uint32_t constant)
{
    struct rnd *fake_rnd = rnd_alloc_fake_fixed(constant);
    
    generate_treasure_type_table(out);
    generate_map(fake_rnd, out);
    generate_each_treasure(fake_rnd, out);
    generate_sample_dungeon(fake_rnd, out);
    generate_random_dungeon(fake_rnd, out);
    generate_character(fake_rnd, out, characteristic_generation_method_simple);
    generate_character(fake_rnd, out, characteristic_generation_method_1);
    generate_character(fake_rnd, out, characteristic_generation_method_2);
    generate_character(fake_rnd, out, characteristic_generation_method_3);
    generate_character(fake_rnd, out, characteristic_generation_method_4);
    generate_character(fake_rnd, out, characteristic_generation_method_general_NPC);
    generate_character(fake_rnd, out, characteristic_generation_method_special_NPC);
    
    rnd_free(fake_rnd);
}