Solitaire for the TI-84 Plus CE!
at calculation 120 lines 3.0 kB view raw
1// Calculation Solitaire / CALCSLTR for the TI-84 Plus CE 2// Copyright (C) 2025 euphory 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see <https://www.gnu.org/licenses/>. 16 17#include "input.h" 18 19#include <stdlib.h> 20#include <keypadc.h> 21#include "variables.h" 22#include "ops.h" 23#include "save.h" 24 25unsigned char down, left, right, up; 26 27bool doInput() 28{ 29 const bool prevSecond = kb_IsDown(kb_Key2nd); 30 const bool prevAlpha = kb_IsDown(kb_KeyAlpha); 31 const bool prevClear = kb_IsDown(kb_KeyClear); 32 33 kb_Scan(); 34 35 up = kb_IsDown(kb_KeyUp) ? up + 1 : 0; 36 down = kb_IsDown(kb_KeyDown) ? down + 1 : 0; 37 left = kb_IsDown(kb_KeyLeft) ? left + 1 : 0; 38 right = kb_IsDown(kb_KeyRight) ? right + 1 : 0; 39 40 const bool select = (kb_IsDown(kb_Key2nd) && !prevSecond); 41 const bool draw = (kb_IsDown(kb_KeyAlpha) && !prevAlpha); 42 const bool clear = (kb_IsDown(kb_KeyClear) && !prevClear); 43 44 if (select) 45 { 46 if (cursorMode == SELECT) 47 { 48 if (canGrabCard()) 49 { 50 grabCard(); 51 cursorMode = DROP; 52 } 53 } 54 else if (canDropCard()) 55 { 56 dropCard(); 57 cursorMode = SELECT; 58 } 59 } 60 else if (clear) 61 { 62 if (canClearCard()) 63 { 64 clearCard(); 65 cursorMode = SELECT; 66 } 67 } 68 else if (draw) 69 { 70 if (cursorMode == SELECT && deckCards > 0) 71 { 72 getNewCard(); 73 orgStack = DECK_ORG; 74 cursorMode = DROP; 75 } 76 } 77 78 unsigned char prevCursorStack = cursorStack; 79 80 if (down == 1 || down > HOLD_TIME) 81 { 82 if (cursorStack < NUM_FREECELLS || !(tableau[cursorStack][cursorIndex + 1] & CARD_EXISTS)) cursorIndex++; 83 } 84 else if (left == 1 || left > HOLD_TIME) 85 { 86 if (cursorStack == 0) cursorStack = NUM_FREECELLS + NUM_TABLSLOTS - 1; // wrap 87 else cursorStack--; 88 } 89 else if (right == 1 || right > HOLD_TIME) 90 { 91 if (cursorStack > NUM_FREECELLS + NUM_TABLSLOTS - 2) cursorStack = 0; // wrap 92 else cursorStack++; 93 } 94 else if (up == 1 || up > HOLD_TIME) 95 { 96 if (cursorIndex > 0) cursorIndex--; 97 } 98 99 if (cursorStack < NUM_FREECELLS) 100 { 101 cursorIndex = 0; 102 } 103 else if (cursorMode == DROP) 104 { 105 maxCursorIndex(); 106 if (cursorStack >= NUM_FREECELLS && (tableau[cursorStack - NUM_FREECELLS][0] & CARD_EXISTS)) cursorIndex++; 107 } 108 else if (cursorStack != prevCursorStack) 109 { 110 maxCursorIndex(); 111 } 112 113 if (kb_IsDown(kb_KeyDel)) 114 { 115 deleteSave(); 116 start(); 117 } 118 119 return !kb_On && progress < 10; 120}