<commit_before>// blockgame
// for NerdKits with ATmega168
// copyright 2011 <NAME>
// license: see LICENSE.txt

#define F_CPU 14745600

#include <stdlib.h>

#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/lcd.h"

// pin definitions for buttons
#define B_LEFT   (1<<PC0)
#define B_DOWN   (1<<PC1)
#define B_UP     (1<<PC2)
#define B_RIGHT  (1<<PC3)
#define B_SELECT (1<<PC4)

// size of the game board
#define MAX_WIDTH 20
#define MAX_HEIGHT 4

// number of high scores we keep around
#define HIGH_SCORES 3
#define INITIALS 3

// living state for the button reader
struct button_states {
    // the stable state (repeated agreeing reads) of the buttons
    uint8_t stable;
    // the most recent read of the buttons
    uint8_t last_read;
};

struct {
    // size of the board
    int width, height;
    // number of unique piece types
    int variety;
    // board state (with enough room for the larges board)
    char board[MAX_HEIGHT][MAX_WIDTH];
} game;

uint16_t score;

// the high score table
struct highscore {
    // initials of the player that made the score
    char initials[INITIALS];
    // the player's score
    uint16_t score;
} highscores[HIGH_SCORES];

// generic "point on the board" structure
struct point {
    int8_t row;
    int8_t column;
    // extra data about this point
    // (used for "activeness" of selection)
    int8_t meta;
};

// wheter or not the animate timer has clicked
volatile int animate = 0;

ISR(TIMER0_COMPA_vect) {
    // time to cycle animations
    animate = 1;
}

void simple_delay(int clicks) {
    while (clicks > 0) {
        if (animate) {
            animate = 0;
            clicks--;
        }
    }
}

// get the LCD setup at boot
void boot_lcd() {
    lcd_init();
    lcd_home();
}

void start_blinking() {
    lcd_set_type_command();
    lcd_write_byte(0x0F);
}

void stop_blinking() {
    lcd_set_type_command();
    lcd_write_byte(0x0C);
}

char random_piece() {
    return 'a'+(rand() % game.variety);
}

// initialize the board
void boot_board() {
    int r,c;
    for (r = 0; r < game.height; r++)
        for (c = 0; c < game.width; c++)
            game.board[r][c] = ' ';
}

// get the input pins setup at boot
void boot_pins() {
    // Set the 6 pins to input mode - four directions + select
    DDRC &= ~(B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);
	  
    // turn on the internal resistors for the pins
    PORTC |= (B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);
}

// configure the animation timer at boot
void boot_timer() {
    // Clear Timer on Compare Match of OCRA
    TCCR0A |= (1<<WGM01);

    // system clock is ~1.47Mhz
    // 14740000/1024 = 14395
    // 14395/60 = 240 (60Hz being target frame rate)
    // choose clock source as system/prescaler1024
    TCCR0B |= (1<<CS02) | (1<<CS00);

    // choose the value for Output Compare A
    OCR0A = 240;
  
    // endable Timer Output Compare Match A Interrupt 0
    TIMSK0 |= (1<<OCIE0A);
}

// clear out all state for the button reader
void clear_button_state(struct button_states* state) {
    state->stable = 0;
    state->last_read = 0;
}

// check the state of the buttons, returns a mask of
// what buttons are now pushed that weren't before
uint8_t read_buttons(struct button_states* state) {
    // get a fresh read
    uint8_t fresh = ~PINC & (B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);

    // factor out bounces by sampling twice before determining
    // what is actually pressed
    uint8_t pressed = state->last_read & fresh;

    // find out what buttons are pushed now that weren't before
    uint8_t newly = (state->stable ^ pressed) & pressed;

    // update state
    state->last_read = fresh;
    state->stable = pressed;

    // reply with newly-pushed buttons
    return newly;
}

// handle any directional button pushes
void move_cursor(uint8_t buttons_pushed,
                 struct point* cursor) {
    if (buttons_pushed & B_UP)
        cursor->row--;
    if (buttons_pushed & B_DOWN)
        cursor->row++;
    if (buttons_pushed & B_LEFT)
        cursor->column--;
    if (buttons_pushed & B_RIGHT)
        cursor->column++;

    if (cursor->row > (game.height-1))
        cursor->row = 0;
    else if (cursor->row < 0)
        cursor->row = (game.height-1);

    if (cursor->column > (game.width-1))
        cursor->column = 0;
    else if (cursor->column < 0)
        cursor->column = (game.width-1);
}<commit_msg>skip the game-over and highscore delays by pressing Select<commit_after>// blockgame
// for NerdKits with ATmega168
// copyright 2011 <NAME>
// license: see LICENSE.txt

#define F_CPU 14745600

#include <stdlib.h>

#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/lcd.h"

// pin definitions for buttons
#define B_LEFT   (1<<PC0)
#define B_DOWN   (1<<PC1)
#define B_UP     (1<<PC2)
#define B_RIGHT  (1<<PC3)
#define B_SELECT (1<<PC4)

// size of the game board
#define MAX_WIDTH 20
#define MAX_HEIGHT 4

// number of high scores we keep around
#define HIGH_SCORES 3
#define INITIALS 3

// living state for the button reader
struct button_states {
    // the stable state (repeated agreeing reads) of the buttons
    uint8_t stable;
    // the most recent read of the buttons
    uint8_t last_read;
};

struct {
    // size of the board
    int width, height;
    // number of unique piece types
    int variety;
    // board state (with enough room for the larges board)
    char board[MAX_HEIGHT][MAX_WIDTH];
} game;

uint16_t score;

// the high score table
struct highscore {
    // initials of the player that made the score
    char initials[INITIALS];
    // the player's score
    uint16_t score;
} highscores[HIGH_SCORES];

// generic "point on the board" structure
struct point {
    int8_t row;
    int8_t column;
    // extra data about this point
    // (used for "activeness" of selection)
    int8_t meta;
};

// wheter or not the animate timer has clicked
volatile int animate = 0;

ISR(TIMER0_COMPA_vect) {
    // time to cycle animations
    animate = 1;
}

// get the LCD setup at boot
void boot_lcd() {
    lcd_init();
    lcd_home();
}

void start_blinking() {
    lcd_set_type_command();
    lcd_write_byte(0x0F);
}

void stop_blinking() {
    lcd_set_type_command();
    lcd_write_byte(0x0C);
}

char random_piece() {
    return 'a'+(rand() % game.variety);
}

// initialize the board
void boot_board() {
    int r,c;
    for (r = 0; r < game.height; r++)
        for (c = 0; c < game.width; c++)
            game.board[r][c] = ' ';
}

// get the input pins setup at boot
void boot_pins() {
    // Set the 6 pins to input mode - four directions + select
    DDRC &= ~(B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);
	  
    // turn on the internal resistors for the pins
    PORTC |= (B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);
}

// configure the animation timer at boot
void boot_timer() {
    // Clear Timer on Compare Match of OCRA
    TCCR0A |= (1<<WGM01);

    // system clock is ~1.47Mhz
    // 14740000/1024 = 14395
    // 14395/60 = 240 (60Hz being target frame rate)
    // choose clock source as system/prescaler1024
    TCCR0B |= (1<<CS02) | (1<<CS00);

    // choose the value for Output Compare A
    OCR0A = 240;
  
    // endable Timer Output Compare Match A Interrupt 0
    TIMSK0 |= (1<<OCIE0A);
}

// check the state of the buttons, returns a mask of
// what buttons are now pushed that weren't before
uint8_t read_buttons(struct button_states* state) {
    // get a fresh read
    uint8_t fresh = ~PINC & (B_LEFT|B_DOWN|B_UP|B_RIGHT|B_SELECT);

    // factor out bounces by sampling twice before determining
    // what is actually pressed
    uint8_t pressed = state->last_read & fresh;

    // find out what buttons are pushed now that weren't before
    uint8_t newly = (state->stable ^ pressed) & pressed;

    // update state
    state->last_read = fresh;
    state->stable = pressed;

    // reply with newly-pushed buttons
    return newly;
}

// clear out all state for the button reader
void clear_button_state(struct button_states* state) {
    state->stable = 0;
    state->last_read = 0;
    // throw away buttons already pressed
    read_buttons(state);
    read_buttons(state);
}

void simple_delay(int clicks) {
    struct button_states button_state;
    clear_button_state(&button_state);

    while (clicks > 0) {
        if (animate) {
            animate = 0;
            clicks--;
            if (read_buttons(&button_state) & B_SELECT)
                break; // skip duration if Select is pushed
        }
    }
}

// handle any directional button pushes
void move_cursor(uint8_t buttons_pushed,
                 struct point* cursor) {
    if (buttons_pushed & B_UP)
        cursor->row--;
    if (buttons_pushed & B_DOWN)
        cursor->row++;
    if (buttons_pushed & B_LEFT)
        cursor->column--;
    if (buttons_pushed & B_RIGHT)
        cursor->column++;

    if (cursor->row > (game.height-1))
        cursor->row = 0;
    else if (cursor->row < 0)
        cursor->row = (game.height-1);

    if (cursor->column > (game.width-1))
        cursor->column = 0;
    else if (cursor->column < 0)
        cursor->column = (game.width-1);
}
{'fraction_non_alphanumeric': 0.11325906509392748, 'fraction_numerical': 0.026430755788553955, 'mean_word_length': 2.676033721397029, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1111906', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3046, 'n_words': 969}