RPN calculator now supports negative values.

This commit is contained in:
Travis Goodspeed 2018-05-24 14:44:25 -04:00
parent 3fa32a17de
commit c4d29fe8a8
2 changed files with 21 additions and 4 deletions

View File

@ -12,8 +12,8 @@
#define STACKSIZE 10
static unsigned long stack[STACKSIZE];
static unsigned long buffer=0;
static long stack[STACKSIZE];
static long buffer=0;
static int bufferdirty=0;
static unsigned int stacki=0;
@ -109,7 +109,7 @@ void rpn_draw(){
//! A button has been pressed for the calculator.
int rpn_keypress(char ch){
unsigned long i, j;
long i, j;
//Do nothing on a keyup event.
if(!ch)

View File

@ -43,6 +43,8 @@ const int lcdmap[10][8]={
//! Bit flags for each of the eight segments.
enum lcdmappos {A=1, B=2, C=4, D=8, E=0x10, F=0x20, G=0x40, DP=0x80};
//! Font for numbers.
const int numfont[]={
A|B|C|D|E|F, //0
@ -125,6 +127,10 @@ void lcd_char(int pos, char c){
}else if(c==' '){
lcd_cleardigit(pos);
return;
}else if(c=='-'){
lcd_cleardigit(pos);
DRAWPOINT(lcdmap[pos][6]); //Set the G segment.
return;
}else if(c=='.'){
lcd_cleardigit(pos);
setperiod(pos,1);
@ -159,7 +165,7 @@ void lcd_string(const char *str){
}
//! Draws a decimal number on the screen.
void lcd_number(long num){
void lcd_unumber(long num){
static long oldnum=0;
static unsigned long bcd=0;
@ -180,6 +186,17 @@ void lcd_number(long num){
lcd_hex(bcd);
}
//! Draws a decimal number on the screen.
void lcd_number(long num){
if(num<0){
lcd_unumber(0-num);
lcd_char(7,'-');
}else{
lcd_unumber(num);
}
}
//! Draws hex on the screen.
void lcd_hex(long num){
/* So in an ideal world, we'd have characters arranged nicely into