Skip to content

Commit d2c3c6a

Browse files
committed
Fixed error reporting. Added duel build.
1 parent 4546de8 commit d2c3c6a

File tree

6 files changed

+143
-49
lines changed

6 files changed

+143
-49
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This is in the public Domain.
44

55
Compile this with CMOC and the fp09 library.
66

7+
RPNS is the single precision calculator, and RPND is the double precision calculator.
8+
79
http://perso.b2b2c.ca/~sarrazip/dev/cmoc.html
810

911
https://github.com/tlindner/fp09

build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
2-
set -e
2+
set -e -x
33

4-
cmoc -o rpn.bin rpn.c -lfp09
4+
cmoc -DDOUBLE -o rpn-d.bin rpn.c -lfp09
5+
cmoc -o rpn-s.bin rpn.c -lfp09
56
decb dskini rpn.dsk
6-
decb copy -2b rpn.bin rpn.dsk,RPN.BIN
7+
decb copy -2b rpn-s.bin rpn.dsk,RPNS.BIN
8+
decb copy -2b rpn-d.bin rpn.dsk,RPND.BIN

rpn-d.bin

12.9 KB
Binary file not shown.

rpn.bin renamed to rpn-s.bin

12.9 KB
Binary file not shown.

rpn.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include <coco.h>
1111
#include "fp09.h"
1212

13-
#if 1 /* Change to 0 to use single precision. */
13+
/* Define SINGLE to use single precision */
14+
#ifdef DOUBLE
1415
typedef fp09_double Float;
1516
#define FLOAT_TYPE_ID fp09_double_type
1617
#else
@@ -67,6 +68,7 @@ int main()
6768
}
6869

6970
// wait for input
71+
check_error( &fpcb );
7072
locate(31,0);
7173
x = waitkey(TRUE);
7274

@@ -133,7 +135,6 @@ int main()
133135
if( blank == FALSE ) stack_input_buffer();
134136
fp09_FADD( &fpcb, stack[1], stack[0], stack[0] );
135137
move_stack_up();
136-
check_error( &fpcb );
137138
}
138139
else if (x == 'S' ) // Subtraction
139140
{
@@ -144,7 +145,6 @@ int main()
144145
fp09_FSUB( &fpcb, stack[1], stack[0], stack[0] );
145146

146147
move_stack_up();
147-
check_error( &fpcb );
148148
}
149149
else if (x == 'M' ) // Multiply
150150
{
@@ -155,7 +155,6 @@ int main()
155155
fp09_FMUL( &fpcb, stack[1], stack[0], stack[0] );
156156

157157
move_stack_up();
158-
check_error( &fpcb );
159158
}
160159
else if (x == 'D' ) // Divide
161160
{
@@ -165,7 +164,6 @@ int main()
165164
if( blank == FALSE ) stack_input_buffer();
166165
fp09_FDIV( &fpcb, stack[1], stack[0], stack[0] );
167166
move_stack_up();
168-
check_error( &fpcb );
169167
}
170168
else if (x == 'O' )
171169
{
@@ -192,7 +190,6 @@ int main()
192190

193191
if( blank == FALSE ) stack_input_buffer();
194192
fp09_FSQRT( &fpcb, stack[0], stack[0] );
195-
check_error( &fpcb );
196193
}
197194
else if (x == 8 ) // delete key;
198195
{
@@ -387,10 +384,6 @@ void stack_input_buffer()
387384
printf( " ");
388385

389386
}
390-
else
391-
{
392-
check_error( &fpcb );
393-
}
394387
}
395388

396389
void draw_stack()
@@ -420,15 +413,24 @@ void move_stack_up()
420413

421414
void check_error( fp09_FPCB *cb )
422415
{
423-
locate(1,0);
424-
printf( "ERROR: ");
425-
if( cb->status & fp09_status_undefined) printf( "UNDEFINED ");
426-
if( cb->status & fp09_status_integer_overflow) printf( "INT OVERFLOW ");
427-
if( cb->status & fp09_status_unordered) printf( "UNORDERED ");
428-
if( cb->status & fp09_status_division_zero) printf( "DIV BY 0 ");
429-
if( cb->status & fp09_status_underflow) printf( "UNDERFLOW ");
430-
if( cb->status & fp09_status_overflow) printf( "OVERFLOW ");
431-
if( cb->status & fp09_status_invalid_operation) printf( "INVALID ");
416+
locate(0,1);
417+
printf( "ERROR: ");
418+
if( cb->status == 0 )
419+
{
420+
printf( "NONE\n" );
421+
}
422+
else
423+
{
424+
if( cb->status & fp09_status_inexact_result) printf( "INEXACT RESULT ");
425+
if( cb->status & fp09_status_undefined) printf( "UNDEFINED ");
426+
if( cb->status & fp09_status_integer_overflow) printf( "INT OVERFLOW ");
427+
if( cb->status & fp09_status_unordered) printf( "UNORDERED ");
428+
if( cb->status & fp09_status_division_zero) printf( "DIV BY 0 ");
429+
if( cb->status & fp09_status_underflow) printf( "UNDERFLOW ");
430+
if( cb->status & fp09_status_overflow) printf( "OVERFLOW ");
431+
if( cb->status & fp09_status_invalid_operation) printf( "INVALID ");
432+
printf("\n");
433+
}
432434

433435
cb->status = 0;
434436
cb->secondary_status = 0;

rpn.dsk

Lines changed: 115 additions & 27 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)