Skip to content

Commit

Permalink
Merge pull request #26 from medvecky/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
medvecky authored Apr 15, 2024
2 parents bffbcea + 623ab0a commit 2dca59b
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 69 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
## Changed

- Optimized command handling functions
- Updated README.md
- Updated README.md

# [v2.1.0] 2024-04-15

## Added

- functions for the operations with the stack
- error handling
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The calculator supports the following operations:
| fabs | absolute value of a number |
| fatn | arctangent in radians |
| fcos | cosine in radians |
| fmul10 | multiply by 10 |
| fmul10 | multiply by 10 |
| fdiv10 | divide by 10 |
| fexp | exponential function |
| fint | get the integer part of a number |
Expand All @@ -26,6 +26,9 @@ The calculator supports the following operations:
| fsqr | square root |
| ftan | tangent in radians |
| fsgn | gives autonomous of the algebraic sign the number (-1; 0; 1) |
| ss | print the content of the stack |
| sc | clear the stack |
| spop | pop the first value of the stack |

Additionally, it accommodates floating-point numbers up to nine digits in both decimal (e.g., 3.14) and scientific (e.g., 8.9e-5) notations.

Expand All @@ -52,7 +55,6 @@ make multicalc

The calculator binary, named multicalc.prg, is located in the /bin directory.


## Operating Manual

The calculator can optionally be run using the [VICE](https://vice-emu.sourceforge.io/) emulator.
Expand Down
51 changes: 39 additions & 12 deletions src/modules/adt_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "adt_stack.h"
#include "math_helper.h"
#include "system_helper.h"

extern FP resultFp;

void Stack_push( StackNodePtr * topPtr, FP value )
{
Expand All @@ -18,11 +21,11 @@ void Stack_push( StackNodePtr * topPtr, FP value )
else
{
FP_printRaw( value );
puts( "not inserted. No memory available.\n" );
puts( "[STACK]: not inserted. No memory available." );
}
}

void Stack_print( StackNodePtr currentPtr )
void Stack_printDebug( StackNodePtr currentPtr )
{
if ( currentPtr == NULL )
{
Expand All @@ -43,20 +46,44 @@ void Stack_print( StackNodePtr currentPtr )
}
}

void Stack_pop( StackNodePtr * topPtr, FP * popValue )
void Stack_print( StackNodePtr currentPtr )
{
if ( currentPtr == NULL )
{
puts( "[STACK]: Empty" );
}
else
{
puts( "--> stack's top <--" );
while ( currentPtr != NULL )
{
memcpy( resultFp, currentPtr->data, sizeof( FP ) );
enableBasicRom();
FP_printResult();
disableBasicRom();
puts( "" );
currentPtr = currentPtr->nextPtr;
}
puts( "--> stack's bottom <--" );
}
}

int Stack_pop( StackNodePtr * topPtr, FP * popValue )
{
StackNodePtr tempPtr;

if ( Stack_isEmpty( *topPtr ) )
{
puts( "Stack is empty. Cannot pop value." );
return;
puts( "[STACK]: Empty" );
return EXIT_FAILURE;
}

tempPtr = *topPtr;
memcpy( *popValue, ( *topPtr )->data, sizeof( FP ) );
*topPtr = ( *topPtr )->nextPtr;
free( tempPtr );

return EXIT_SUCCESS;
}

bool Stack_isEmpty( StackNodePtr topPtr )
Expand All @@ -68,7 +95,7 @@ void Stack_getTop( StackNodePtr topPtr, FP * topValue)
{
if ( Stack_isEmpty( topPtr ) )
{
puts( "Stack is empty. Cannot pop value." );
puts( "[STACK]: Empty" );
return;
}

Expand All @@ -77,13 +104,13 @@ void Stack_getTop( StackNodePtr topPtr, FP * topValue)

void Stack_free( StackNodePtr * topPtr )
{
StackNodePtr tempPtr = *topPtr;
StackNodePtr nextPtr;
while ( tempPtr != NULL )
StackNodePtr tempPtr;

while ( *topPtr != NULL)
{
nextPtr = ( *tempPtr ).nextPtr;
tempPtr = *topPtr;
*topPtr = ( *topPtr )->nextPtr;
free( tempPtr );
tempPtr = nextPtr;
}
}
}

3 changes: 2 additions & 1 deletion src/modules/adt_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;

void Stack_push( StackNodePtr * topPtr, FP value );
void Stack_printDebug( StackNodePtr currentPtr );
void Stack_print( StackNodePtr currentPtr );
void Stack_pop( StackNodePtr * topPtr, FP * popValue );
int Stack_pop( StackNodePtr * topPtr, FP * popValue );
bool Stack_isEmpty( StackNodePtr topPtr );
void Stack_getTop( StackNodePtr topPtr, FP * topValue );
void Stack_free( StackNodePtr * topPtr );
Expand Down
6 changes: 6 additions & 0 deletions src/modules/math_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ void FP_mult( void )

void FP_div( void )
{
if ( arg1Fp[ 0 ] == 0 && arg1Fp[ 1 ] == 0 && arg1Fp[ 2 ] == 0 && arg1Fp[ 3 ] == 0 && arg1Fp[ 4 ] == 0 )
{
puts( "[FP]: Division by zero" );
return;
}

FP_arg1ToFac();
__asm__ ( "lda #<%v", arg2Fp );
__asm__ ( "ldy #>%v", arg2Fp );
Expand Down
2 changes: 1 addition & 1 deletion src/modules/math_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

#define MAX_ARGUMENT_LENGTH 12
#define MAX_ARGUMENT_LENGTH 20

typedef uint8_t FP[5];

Expand Down
Loading

0 comments on commit 2dca59b

Please sign in to comment.