add shift key and ability to calculate ln()

This commit is contained in:
Jeff Wang 2019-10-02 22:47:53 -04:00
parent 9fc462ca94
commit cb92a82f4b
3 changed files with 29 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#define STACK_T 3
uint8_t NoLift = 0;
uint8_t IsShifted = 0;
//stack "grows" towards 0
__xdata dec80 Stack[STACK_SIZE]; //0->x, 1->y, 2->z, 3->t initially
@ -60,6 +61,10 @@ static void do_binary_op(void (*f_ptr)(void)){
pop();
}
static void toggle_shifted(void){
IsShifted ^= 1;
}
void process_cmd(char cmd){
//turn off backlight before start of processing
backlight_off();
@ -108,6 +113,18 @@ void process_cmd(char cmd){
copy_decn(&stack(STACK_Y), &tmp);
}
} break;
//////////
case 'm':{ //use as shift
toggle_shifted();
} break;
//////////
case '8':{
if (IsShifted && !decn_is_nan(&stack(STACK_X))){ //ln(x)
copy_decn(&AccDecn, &stack(STACK_X));
ln_decn();
copy_decn(&stack(STACK_X), &AccDecn);
toggle_shifted();
}
} break;
//////////
} //switch(cmd)

View File

@ -19,6 +19,7 @@ void process_cmd(char cmd);
//push_decn is equivalent to "set_x()" if no_lift is true
void push_decn(__xdata const char* signif_str, exp_t exponent);
extern uint8_t NoLift;
extern uint8_t IsShifted;
void clear_x(void);
__xdata dec80* get_x(void);

View File

@ -125,7 +125,7 @@ static void latch_on(void)
__xdata char EntryBuf[MAX_CHARS_PER_LINE + 1];
__xdata uint8_t ExpBuf[2];
__xdata const char VER_STR[32+1] = "STC RPN Calculator v1.03";
__xdata const char VER_STR[32+1] = "STC RPN Calculator v1.04";
#ifdef DESKTOP
static void print_entry_bufs(int entering_exp){
@ -276,7 +276,9 @@ int main()
case '7': //fallthrough
case '8': //fallthrough
case '9': {
if (entering_exp >= ENTERING_EXP){
if (IsShifted){
process_cmd(KEY_MAP[i_key]);
} else if (entering_exp >= ENTERING_EXP){
if (exp_i == 0){
ExpBuf[0] = KEY_MAP[i_key] - '0';
exp_i = 1;
@ -342,7 +344,7 @@ int main()
} break;
//////////
case 'c': {
if (entering_exp == ENTERING_DONE){
if (IsShifted || entering_exp == ENTERING_DONE){
//clear
clear_x();
NoLift = 1;
@ -479,6 +481,12 @@ int main()
TERMIO_PutChar(ExpBuf[0] + '0');
}
LCD_ClearToEnd(1);
//print shifted status
if (IsShifted){
TERMIO_PutChar('^');
}
#ifdef DESKTOP
print_lcd();
printf("entry_i=%d,exp_i=%d\n", entry_i, exp_i);