Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
NumDrive levels button and open levels, Tetris input fixes, home screen shots
Mason363e7b7df7ebce0
diff --git a/README.md b/README.mdindex b95d9d36..898db7f4 100644--- a/README.md+++ b/README.md@@ -42,6 +42,10 @@ Click a file to download it. Not sure which one? Take the first.<td width="120" align="center"><img src="docs/media/icon-matrices.png" width="64" alt="A Matrices icon in the calculator's style"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumPlay-Matrices.nwa">NumPlay-Matrices.nwa</a><br>The same app, in disguise. It looks like a math app called <b>Matrices</b>, next to the calculator's own apps.</td></tr>+ <tr>+ <td></td>+ <td><img src="docs/media/home_invisible.png" width="240" alt="The calculator's home screen with NumPlay-Invisible installed: the spot after Settings looks empty"> <img src="docs/media/home_matrices.png" width="240" alt="The calculator's home screen with NumPlay-Matrices installed, next to the calculator's own apps"><br><sub>On the home screen: the invisible one is really there, in the empty spot after Settings. The Matrices one sits among the calculator's own apps.</sub></td>+ </tr><tr><td width="120" align="center"><img src="docs/media/thumb_numdash.png" width="112" alt="NumDash"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumDash.nwa">NumDash.nwa</a><br>Only NumDash: jump to the beat</td>diff --git a/docs/media/home_invisible.png b/docs/media/home_invisible.pngnew file mode 100644index 00000000..ac222ff5Binary files /dev/null and b/docs/media/home_invisible.png differdiff --git a/docs/media/home_matrices.png b/docs/media/home_matrices.pngnew file mode 100644index 00000000..d523d322Binary files /dev/null and b/docs/media/home_matrices.png differdiff --git a/games/numdrive/src/main.c b/games/numdrive/src/main.cindex bf81825d..aa4f255f 100644--- a/games/numdrive/src/main.c+++ b/games/numdrive/src/main.c@@ -95,7 +95,6 @@ static void hud_post(uint16_t *px, int y, int n) {else hud_draw(px, y, n);}-extern bool level_unlocked(int i);#ifdef ARMTESTextern char **environ;@@ -191,13 +190,22 @@ int main(int argc, char **argv) {#endifrender_frame(hud_post);} else if (state == ST_CARD) {- if (card_buttons() == 2) {- if ((hit & KEY(K_LEFT)) && sel) sel = 0, dirty = true;- if ((hit & KEY(K_RIGHT)) && !sel) sel = 1, dirty = true;+ int nb = card_buttons();+ if (nb > 1) {+ if ((hit & KEY(K_LEFT)) && sel > 0) sel--, dirty = true;+ if ((hit & KEY(K_RIGHT)) && sel < nb - 1) sel++, dirty = true;} else {sel = 1;}- if (hit & (KEY(K_OK) | KEY(K_EXE))) {+ bool ok = (hit & (KEY(K_OK) | KEY(K_EXE))) != 0;+ if ((hit & KEY(K_BACK)) || (ok && kind == CARD_PAUSE && sel == 2)) { /* the "<" arrow or Levels */+ state = ST_LEVELS;+ lsel = cur;+ lscroll = lsel / 5 - 2 < 0 ? 0 : lsel / 5 - 2;+ dirty = true;+ continue;+ }+ if (ok) {if (kind == CARD_PAUSE && sel == 1) {state = ST_PLAY;} else {@@ -207,13 +215,6 @@ int main(int argc, char **argv) {}continue;}- if (hit & KEY(K_BACK)) { /* the "<" arrow: level list */- state = ST_LEVELS;- lsel = cur;- lscroll = lsel / 5 - 2 < 0 ? 0 : lsel / 5 - 2;- dirty = true;- continue;- }if (kind != CARD_PAUSE)for (int s = 0; s < steps; s++) sim_step(0);bool full = dirty || anim <= 13;@@ -226,7 +227,7 @@ int main(int argc, char **argv) {if (hit & KEY(K_RIGHT)) lsel++;if (hit & KEY(K_UP)) lsel -= 5;if (hit & KEY(K_DOWN)) lsel += 5;- if (lsel < 0 || lsel >= nlevels || !level_unlocked(lsel)) lsel = old;+ if (lsel < 0 || lsel >= nlevels) lsel = old;if (lsel != old) dirty = true;if (lsel / 5 < lscroll) lscroll = lsel / 5, dirty = true;if (lsel / 5 > lscroll + 3) lscroll = lsel / 5 - 3, dirty = true;diff --git a/games/numdrive/src/ui.c b/games/numdrive/src/ui.cindex 5e89c92d..5e769ab7 100644--- a/games/numdrive/src/ui.c+++ b/games/numdrive/src/ui.c@@ -23,44 +23,23 @@#define C_GREEN_D RGB(0x26, 0x8f, 0x34)#define C_TILE_B RGB(0x00, 0x7a, 0xee)#define C_TILE_BD RGB(0x00, 0x58, 0xc0)-#define C_LOCK RGB(0x68, 0x76, 0x95)-#define C_LOCK_D RGB(0x56, 0x62, 0x7e)#define C_SHADOW RGB(0x10, 0x1c, 0x58)#define C_TITLE_O RGB(0x19, 0x1a, 0x1b)/* ------------------------------------------------------------------- HUD */static int hud_t;-static uint8_t hud_btn, hud_used;-static int fade_l, fade_r;+static uint8_t hud_btn;float hud_score, hud_coins;void hud_reset(void) {hud_t = 0;hud_score = hud_coins = -1;- hud_btn = hud_used = 0;- fade_l = fade_r = 32;+ hud_btn = 0;}void hud_tick(uint8_t buttons) {hud_t++;hud_btn = buttons;- hud_used |= buttons;- if ((hud_used & 1) && fade_l > 0) fade_l -= 4;- if ((hud_used & 2) && fade_r > 0) fade_r -= 4;-}--static void hint_box(int x, int y, const Icon *ic, bool on) {- if (on) {- g_rect(x, y, 18, 18, C_WHITE, 29);- g_icon(ic, x + 6, y + 6, sky565, 32);- } else {- g_rect(x + 2, y + 2, 14, 14, C_WHITE, 10);- g_rect(x, y, 18, 2, C_WHITE, 20);- g_rect(x, y + 16, 18, 2, C_WHITE, 20);- g_rect(x, y + 2, 2, 14, C_WHITE, 20);- g_rect(x + 16, y + 2, 2, 14, C_WHITE, 20);- g_icon(ic, x + 6, y + 6, C_WHITE, 24);- }}/* Set Score counter text: white halo, dark outline and a face with a darker extruded bottom */@@ -159,19 +138,13 @@ void hud_draw(uint16_t *px, int y, int n) {}}draw_counters();- if (y + n > 104 && y < 122) {- hint_box(16, 104, &ic_left, hud_btn & 1);- hint_box(286, 104, &ic_right, (hud_btn & 2) != 0);- }if (y + n > 180 && y < 216) {- if (fade_l > 0) {- g_icon(&ic_back, 36, 184, C_WHITE, fade_l * 14 / 32);- g_icon(&ic_back, 37, 184, C_WHITE, fade_l * 14 / 32);- }- if (fade_r > 0) {- g_icon(&ic_next, 274, 184, C_WHITE, fade_r * 14 / 32);- g_icon(&ic_next, 275, 184, C_WHITE, fade_r * 14 / 32);- }+ /* the driving arrows: faint, and white while their key is held */+ int al = hud_btn & 1 ? 32 : 14, ar = hud_btn & 2 ? 32 : 14;+ g_icon(&ic_back, 36, 184, C_WHITE, al);+ g_icon(&ic_back, 37, 184, C_WHITE, al);+ g_icon(&ic_next, 274, 184, C_WHITE, ar);+ g_icon(&ic_next, 275, 184, C_WHITE, ar);}}@@ -360,7 +333,7 @@ void card_setup(int kind, int lvl) {}}-int card_buttons(void) { return cd.kind == CARD_LOSE ? 1 : 2; }+int card_buttons(void) { return cd.kind == CARD_LOSE ? 1 : cd.kind == CARD_PAUSE ? 3 : 2; }/* 2x2 bilinear sample of a text run, returns alpha 0..32 */static int run_texel(const Run *r, int x, int y) {@@ -405,28 +378,36 @@ static void card_btns(int sel, int yb) {g_icon(&ic_play, 160 - 6, yb + 3, C_WHITE, 32);g_text_c(&font_s, 160, yb + 25 - font_s.base, "Retry", C_WHITE, 32);} else {- const int ws = 46;- g_rrect(x0 - 1, yb - 1, w + 2, h + 2, r + 1, C_BLACK, 32);- g_rrect(x0, yb, w, h, r, C_BLUE_D, 32);- g_rrect(x0, yb, w, h - 3, r, C_BLUE, 32);- /* grey restart segment on the left */+ /* Restart (grey) | Resume or Next Level (blue), and Levels (grey) on the pause card */+ const bool paused = cd.kind == CARD_PAUSE;+ const int ws = 46, wl = paused ? 50 : 0, wb = paused ? 192 : w, xb = 160 - wb / 2;+ g_rrect(xb - 1, yb - 1, wb + 2, h + 2, r + 1, C_BLACK, 32);+ g_rrect(xb, yb, wb, h, r, C_BLUE_D, 32);+ g_rrect(xb, yb, wb, h - 3, r, C_BLUE, 32);for (int yy = yb; yy < yb + h; yy++) {if (yy < gc.y0 || yy >= gc.y1) continue;uint16_t *p = gc.px + (yy - gc.y0) * SCREEN_W;- for (int x = x0; x < x0 + ws; x++) {+ for (int x = xb; x < xb + wb; x++) {+ if (x >= xb + ws && x < xb + wb - wl) continue;uint16_t c = p[x];if (c == C_BLUE) p[x] = C_GRAY;else if (c == C_BLUE_D) p[x] = C_GRAY_D;else if (c != C_BLACK) p[x] = mix565(c, C_GRAY, 20);}}- g_icon(&ic_restart, x0 + ws / 2 - 7, yb + 3, C_WHITE, 32);- g_text_c(&font_s, x0 + ws / 2, yb + 25 - font_s.base, "Restart", C_WHITE, 32);- int cx = x0 + ws + (w - ws) / 2;+ g_icon(&ic_restart, xb + ws / 2 - 7, yb + 3, C_WHITE, 32);+ g_text_c(&font_s, xb + ws / 2, yb + 25 - font_s.base, "Restart", C_WHITE, 32);+ int cx = xb + ws + (wb - ws - wl) / 2;g_icon(&ic_play, cx - 7, yb + 3, C_WHITE, 32);- g_text_c(&font_s, cx, yb + 25 - font_s.base, cd.kind == CARD_PAUSE ? "Resume" : "Next Level", C_WHITE, 32);+ g_text_c(&font_s, cx, yb + 25 - font_s.base, paused ? "Resume" : "Next Level", C_WHITE, 32);+ if (paused) {+ int lx = xb + wb - wl / 2;+ for (int k = 0; k < 4; k++) g_rect(lx - 6 + (k & 1) * 7, yb + 4 + (k >> 1) * 7, 5, 5, C_WHITE, 32);+ g_text_c(&font_s, lx, yb + 25 - font_s.base, "Levels", C_WHITE, 32);+ }/* focus ring */- int fx = sel == 0 ? x0 : x0 + ws, fw = sel == 0 ? ws : w - ws;+ int fx = sel == 0 ? xb : sel == 1 ? xb + ws : xb + wb - wl;+ int fw = sel == 0 ? ws : sel == 1 ? wb - ws - wl : wl;g_rect(fx + 1, yb + 1, fw - 2, 1, C_WHITE, 26);g_rect(fx + 1, yb + h - 5, fw - 2, 1, C_WHITE, 26);g_rect(fx + 1, yb + 1, 1, h - 5, C_WHITE, 26);@@ -534,8 +515,6 @@ void card_draw(int anim, int sel, bool full) {#define GX (160 - (5 * PITCH - (PITCH - TILE)) / 2)#define GY 46-bool level_unlocked(int i) { return i == 0 || lvl_done(i) || lvl_done(i - 1); }-void levels_draw(int sel, int scroll) {for (int sy = 0; sy < SCREEN_H; sy += STRIP_H) {int n = SCREEN_H - sy < STRIP_H ? SCREEN_H - sy : STRIP_H;@@ -559,17 +538,13 @@ void levels_draw(int sel, int scroll) {int i = (scroll + row) * 5 + col;if (i >= nlevels) break;int lx = GX + col * PITCH;- uint16_t top, bot;- bool unl = level_unlocked(i);- if (lvl_done(i)) top = C_GREEN, bot = C_GREEN_D;- else if (unl) top = C_TILE_B, bot = C_TILE_BD;- else top = C_LOCK, bot = C_LOCK_D;- if (fade < 32 || !unl) {+ /* every level can be played; the ones already finished are green */+ uint16_t top = lvl_done(i) ? C_GREEN : C_TILE_B, bot = lvl_done(i) ? C_GREEN_D : C_TILE_BD;+ if (fade < 32) {/* translucent tiles over the background */- int a = unl ? fade : fade * 24 / 32;- g_rrect(lx - 1, ly - 1, TILE + 2, TILE + 2, 6, C_BLACK, a);- g_rrect(lx, ly, TILE, TILE, 5, bot, a);- g_rrect(lx, ly, TILE, TILE - 3, 5, top, a);+ g_rrect(lx - 1, ly - 1, TILE + 2, TILE + 2, 6, C_BLACK, fade);+ g_rrect(lx, ly, TILE, TILE, 5, bot, fade);+ g_rrect(lx, ly, TILE, TILE - 3, 5, top, fade);} else {g_button(lx, ly, TILE, TILE, 5, top, bot, i == sel);}@@ -580,7 +555,7 @@ void levels_draw(int sel, int scroll) {num[k++] = (char)('0' + v % 10);num[k] = 0;g_text_c(&font_m, lx + TILE / 2, ly + (TILE - 3) / 2 - (font_m.cap_top + font_m.base) / 2 + 1, num, C_WHITE,- unl ? fade : fade * 20 / 32);+ fade);}}if (sy < 110 && sy + n > 84) {diff --git a/games/numdrive/src/ui.h b/games/numdrive/src/ui.hindex 244cefcc..ed97834a 100644--- a/games/numdrive/src/ui.h+++ b/games/numdrive/src/ui.h@@ -17,7 +17,7 @@ void ui_capture_background(void);/* card screen; anim counts frames since the card appeared; sel is the focused button */void card_setup(int kind, int level);void card_draw(int anim, int sel, bool full);-int card_buttons(void); /* number of buttons (1 or 2) */+int card_buttons(void); /* number of buttons (1 to 3) *//* level select */void levels_draw(int sel, int scroll);diff --git a/games/tetris/README.md b/games/tetris/README.mdindex a2ea57d1..2201b89f 100644--- a/games/tetris/README.md+++ b/games/tetris/README.md@@ -18,9 +18,9 @@ The original is released into the public domain ([UNLICENSE](UNLICENSE)). This c| Left / Right, or 4 / 6 | Move || Down, or 2 | Soft drop || Up, or 8 | Hard drop |-| OK / Back | Rotate left / right |+| OK / Toolbox | Rotate left / right || ⌫ | Hold |-| Shift | Pause |+| Back | Pause, with Quit game |## Builddiff --git a/games/tetris/numworks_utils/src/eadk.rs b/games/tetris/numworks_utils/src/eadk.rsindex d1569b6d..5cdf4bbf 100644--- a/games/tetris/numworks_utils/src/eadk.rs+++ b/games/tetris/numworks_utils/src/eadk.rs@@ -239,29 +239,105 @@ pub mod display {}pub mod keyboard {- use super::State;+ use super::{key, timing, State};++ /// A key has to stay up this long to count as released, so a contact that+ /// flickers while it is held never makes a second press.+ const RELEASE_MS: u32 = 30;+ /// Up (the hard drop in Tetris) is easy to brush while pressing another+ /// arrow on the round arrow pad. It is ignored when it goes down within+ /// NEAR_MS of another arrow, and only counts once it has been held for+ /// UP_MS without another arrow being pressed meanwhile.+ const NEAR_MS: u32 = 80;+ const UP_MS: u32 = 40;+ const OTHER_ARROWS: u64 = 1 << key::LEFT | 1 << key::RIGHT | 1 << key::DOWN;++ #[derive(PartialEq, Eq)]+ enum Up {+ Idle,+ Waiting,+ On,+ Ignored,+ }++ struct Filter {+ last_down: [u32; 64],+ prev: u64,+ arrow_at: u32,+ up: Up,+ up_at: u32,+ }++ static mut FILTER: Filter = Filter {+ last_down: [0; 64],+ prev: 0,+ arrow_at: 0,+ up: Up::Idle,+ up_at: 0,+ };- /// The keys held down. 8, 4, 6 and 2 on the number pad also count as the- /// up, left, right and down arrows.+ /// The keys held down, debounced. 8, 4, 6 and 2 on the number pad also+ /// count as the up, left, right and down arrows.#[must_use]pub fn scan() -> State {let raw = unsafe { eadk_keyboard_scan() };// Home and On/Off leave the app from anywhere (see crate::app)- if raw >> super::key::HOME & 1 != 0 || raw >> 8 & 1 != 0 {+ if raw >> key::HOME & 1 != 0 || raw >> 8 & 1 != 0 {crate::app::leave();}let mut state = raw;for (pad, arrow) in [- (super::key::EIGHT, super::key::UP),- (super::key::FOUR, super::key::LEFT),- (super::key::SIX, super::key::RIGHT),- (super::key::TWO, super::key::DOWN),+ (key::EIGHT, key::UP),+ (key::FOUR, key::LEFT),+ (key::SIX, key::RIGHT),+ (key::TWO, key::DOWN),] {if raw >> pad & 1 != 0 {state |= 1 << arrow;}}- State::new(state)+ State::new(filter(state))+ }++ fn filter(raw: u64) -> u64 {+ // SAFETY: one thread, and nothing keeps a reference across calls+ let f = unsafe { &mut *core::ptr::addr_of_mut!(FILTER) };+ let now = (timing::millis() as u32).max(1);+ let mut held = raw;+ for k in 0..64 {+ if raw >> k & 1 != 0 {+ f.last_down[k] = now;+ } else if f.last_down[k] != 0 && now.wrapping_sub(f.last_down[k]) < RELEASE_MS {+ held |= 1 << k;+ }+ }+ let arrow_pressed = held & OTHER_ARROWS & !f.prev != 0;+ if arrow_pressed {+ f.arrow_at = now;+ }+ f.prev = held;+ let up = 1u64 << key::UP;+ if held & up == 0 {+ f.up = Up::Idle;+ return held;+ }+ if f.up == Up::Idle {+ if f.arrow_at != 0 && now.wrapping_sub(f.arrow_at) < NEAR_MS {+ f.up = Up::Ignored;+ } else {+ f.up = Up::Waiting;+ f.up_at = now;+ }+ } else if f.up == Up::Waiting && arrow_pressed {+ f.up = Up::Ignored;+ }+ if f.up == Up::Waiting && now.wrapping_sub(f.up_at) >= UP_MS {+ f.up = Up::On;+ }+ if f.up != Up::On {+ held &= !up;+ }+ held}extern "C" {diff --git a/games/tetris/numworks_utils/src/menu.rs b/games/tetris/numworks_utils/src/menu.rsindex b48d8655..77bc636c 100644--- a/games/tetris/numworks_utils/src/menu.rs+++ b/games/tetris/numworks_utils/src/menu.rs@@ -45,7 +45,8 @@ const CHOICES_WITH_SAVE: &[&str] = &["Exit\0",];-fn confirm_dialog(prompt: &str, cfg: &ColorConfig) -> bool {+/// Asks a yes/no question; No is selected first, and Back answers No.+pub fn confirm_dialog(prompt: &str, cfg: &ColorConfig) -> bool {let dialog_w = 200u16;let dialog_h = (LARGE_CHAR_HEIGHT * 3) + 16;let dialog_x = (SCREEN_WIDTH - dialog_w) / 2;@@ -235,8 +236,10 @@ fn start_menu_single_slot<T: GameSave>(controls(controls_text, cfg);}_ => {- fading(FADING_TIME);- return StartMenuAction::Exit;+ if confirm_dialog("Quit game?\0", cfg) {+ fading(FADING_TIME);+ return StartMenuAction::Exit;+ }}}} else {@@ -258,8 +261,10 @@ fn start_menu_single_slot<T: GameSave>(controls(controls_text, cfg);}_ => {- fading(FADING_TIME);- return StartMenuAction::Exit;+ if confirm_dialog("Quit game?\0", cfg) {+ fading(FADING_TIME);+ return StartMenuAction::Exit;+ }}}}@@ -332,7 +337,7 @@ pub fn pause_menu(cfg: &ColorConfig, y_offset: i16) -> u8 {selection(cfg,&MenuConfig {- choices: &["Resume\0", "Menu\0", "Exit\0"],+ choices: &["Resume\0", "Menu\0", "Quit game\0"],rect_margins: (20, 10),dimensions: (SCREEN_WIDTH * 2 / 5,diff --git a/games/tetris/tetris/src/data/tetris_controls.txt b/games/tetris/tetris/src/data/tetris_controls.txtindex 7dd82b18..d474a2eb 100644--- a/games/tetris/tetris/src/data/tetris_controls.txt+++ b/games/tetris/tetris/src/data/tetris_controls.txt@@ -4,9 +4,9 @@- <LEFT> and <RIGHT> to move- <DOWN> for soft drop- <UP> for hard drop- - <OK> & <BACK> to rotate left and right+ - <OK> & <TOOLBOX> to rotate left and right- <BACKSPACE> (<clear>) to hold the tetri- - <SHIFT> to pause+ - <BACK> to pauseEvery full line disappearsGet more points by clearingdiff --git a/games/tetris/tetris/src/game_tetris.rs b/games/tetris/tetris/src/game_tetris.rsindex 2f19872d..fc72b0cf 100644--- a/games/tetris/tetris/src/game_tetris.rs+++ b/games/tetris/tetris/src/game_tetris.rs@@ -6,7 +6,7 @@ use numworks_utils::{},graphical::{draw_centered_string, ColorConfig},menu::{- pause_menu, selection,+ confirm_dialog, pause_menu, selection,settings::{write_values_to_file, Setting},start_menu_with_save, MenuConfig, StartMenuAction,},@@ -171,38 +171,42 @@ pub const CASE_SIZE: u16 = 12;pub const PLAYFIELD_HEIGHT: u16 = 20;pub const PLAYFIELD_WIDTH: u16 = 10;-const ROTATE_SPEED: u64 = 150;-const DELAYED_AUTO_SHIFT: u64 = 167;-const AUTO_MOVE_SPEED: u64 = 33;+/* a held arrow starts repeating after DELAYED_AUTO_SHIFT, then moves every AUTO_MOVE_SPEED:+ * a bit slower than arcade timings, as calculator keys are pressed longer */+const DELAYED_AUTO_SHIFT: u64 = 220;+const AUTO_MOVE_SPEED: u64 = 40;const SOFT_DROP_SPEED: u64 = 33;const LEFT_KEY: u32 = key::LEFT;const RIGHT_KEY: u32 = key::RIGHT;const SOFT_DROP_KEY: u32 = key::DOWN;const HARD_DROP_KEY: u32 = key::UP;-const PAUSE_KEY: u32 = key::SHIFT;-const RIGHT_ROTATION_KEY: u32 = key::BACK;+const PAUSE_KEY: u32 = key::BACK;+const RIGHT_ROTATION_KEY: u32 = key::TOOLBOX;const LEFT_ROTATION_KEY: u32 = key::OK;const HOLD_KEY: u32 = key::BACKSPACE;const DEATH_MENU: MenuConfig = MenuConfig {- choices: &["Replay\0", "Menu\0", "Exit\0"],+ choices: &["Replay\0", "Menu\0", "Quit game\0"],rect_margins: (20, 10),dimensions: (CASE_SIZE * (PLAYFIELD_WIDTH + 2), CASE_SIZE * 10),offset: (0, 60),- back_key_return: 2,+ back_key_return: 1,};struct Timings {pub fall: u64,pub side_move: u64,- pub rotate: u64,}+/// Keys held since they last did something: rotating, holding and pausing+/// need a new press each time.struct Buttons {pub side_move: bool,pub rotate: bool,pub soft_drop: bool,+ pub hold: bool,+ pub pause: bool,}impl Buttons {@@ -222,6 +226,12 @@ impl Buttons {if self.soft_drop && !keyboard_state.key_down(SOFT_DROP_KEY) {self.soft_drop = false;}+ if self.hold && !keyboard_state.key_down(HOLD_KEY) {+ self.hold = false;+ }+ if self.pause && !keyboard_state.key_down(PAUSE_KEY) {+ self.pause = false;+ }}}@@ -252,12 +262,15 @@ pub fn game(let mut timings = Timings {fall: timing::millis(),side_move: timing::millis(),- rotate: timing::millis(),};+ // keys already down when the game starts wait for a new press+ let start_keys = keyboard::scan();let mut buttons = Buttons {side_move: false,- rotate: false,+ rotate: start_keys.key_down(LEFT_ROTATION_KEY) || start_keys.key_down(RIGHT_ROTATION_KEY),soft_drop: false,+ hold: start_keys.key_down(HOLD_KEY),+ pause: start_keys.key_down(PAUSE_KEY),};let mut blockers = Blockers {hold: false,@@ -334,14 +347,15 @@ pub fn game(draw_ghost_tetri(¤t_tetri, &grid, false, ghost_piece);draw_tetrimino(¤t_tetri, false);-- timings.side_move = timing::millis();- buttons.side_move = true;}- } else if (!buttons.rotate || (timings.rotate + ROTATE_SPEED < timing::millis()))+ // the press counts even against a wall, so it never moves twice+ timings.side_move = timing::millis();+ buttons.side_move = true;+ } else if !buttons.rotate&& (keyboard_state.key_down(RIGHT_ROTATION_KEY)|| keyboard_state.key_down(LEFT_ROTATION_KEY)){+ buttons.rotate = true;let new_tetri = can_rotate(keyboard_state.key_down(RIGHT_ROTATION_KEY),¤t_tetri,@@ -355,13 +369,11 @@ pub fn game(draw_ghost_tetri(¤t_tetri, &grid, false, ghost_piece);draw_tetrimino(¤t_tetri, false);-- timings.rotate = timing::millis();- buttons.rotate = true;}- } else if !blockers.hold && keyboard_state.key_down(HOLD_KEY) {+ } else if !blockers.hold && !buttons.hold && keyboard_state.key_down(HOLD_KEY) {let temp = current_tetri.clone();blockers.hold = true;+ buttons.hold = true;draw_tetrimino(¤t_tetri, true);draw_ghost_tetri(¤t_tetri, &grid, true, ghost_piece);@@ -432,7 +444,10 @@ pub fn game(true,);}- let action = selection(&COLOR_CONFIG, &DEATH_MENU, false);+ let mut action = selection(&COLOR_CONFIG, &DEATH_MENU, false);+ if action == 2 && !confirm_dialog("Quit game?\0", &COLOR_CONFIG) {+ action = 1; // not quitting: back to the Tetris menu+ }// Ensure the save is deleted regardless of selection option chosendelete_save("tetris", None);break 'gameloop action;@@ -494,11 +509,9 @@ pub fn game(}blockers.check_and_clear(&buttons);- if keyboard_state.key_down(PAUSE_KEY) {- let action = pause_menu(&COLOR_CONFIG, 0);- if action != 0 {- return action;- } else {+ if keyboard_state.key_down(PAUSE_KEY) && !buttons.pause {+ buttons.pause = true;+ let redraw = || {wait_for_vblank();draw_stable_ui(level, level_lines, score, *high_score);wait_for_vblank();@@ -517,7 +530,19 @@ pub fn game(draw_held_tetrimino(held_tetri_);}draw_next_tetrimino(&next_tetri);+ };+ // Quit game asks first; saying no comes back to the pause menu+ let action = loop {+ let a = pause_menu(&COLOR_CONFIG, 0);+ if a != 2 || confirm_dialog("Quit game?\0", &COLOR_CONFIG) {+ break a;+ }+ redraw();+ };+ if action != 0 {+ return action;}+ redraw();}display::wait_for_vblank();}