Skip to content

Commit 4546de8

Browse files
committed
Add single precision compile time option from Pierre Sarrazin
1 parent 51dfe18 commit 4546de8

File tree

3 files changed

+85
-72
lines changed

3 files changed

+85
-72
lines changed

rpn.bin

-9 Bytes
Binary file not shown.

rpn.c

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

13+
#if 1 /* Change to 0 to use single precision. */
14+
typedef fp09_double Float;
15+
#define FLOAT_TYPE_ID fp09_double_type
16+
#else
17+
typedef fp09_single Float;
18+
#define FLOAT_TYPE_ID fp09_single_type
19+
#endif
20+
1321
byte is_numeric( byte x );
14-
void print_double( fp09_double *d );
22+
void print_float( Float *d );
1523
void stack_input_buffer();
1624
void draw_stack();
1725
void move_stack_up();
1826
void check_error( fp09_FPCB *cb );
1927
void go_help();
2028

21-
fp09_double stack[8];
29+
Float stack[8];
2230
byte input_buffer[31];
2331
byte blank;
2432
byte decimal_point;
25-
fp09_FPCB fpcb = {fp09_double_type, 0, 0, 0, trap_6839};
33+
fp09_FPCB fpcb = {FLOAT_TYPE_ID, 0, 0, 0, trap_6839};
2634

2735
int main()
2836
{
@@ -39,6 +47,9 @@ int main()
3947

4048
decimal_point = FALSE;
4149

50+
locate(0, 15);
51+
printf("SIZE OF FLOAT TYPE: %u BYTES", sizeof(Float));
52+
4253
draw_stack();
4354

4455
while( x != 'E' )
@@ -161,18 +172,18 @@ int main()
161172
// shift stack up
162173
for( c=0; c<7; c++ )
163174
{
164-
memcpy(stack[c], stack[c+1], 8);
175+
memcpy(stack[c], stack[c+1], sizeof(Float));
165176
}
166177

167-
memset( stack[7], 0, 8 );
178+
memset( stack[7], 0, sizeof(Float) );
168179
}
169180
else if( x=='W' )
170181
{
171-
fp09_double temp;
182+
Float temp;
172183

173-
memcpy( temp, stack[0], sizeof(fp09_double));
174-
memcpy( stack[0], stack[1], sizeof(fp09_double));
175-
memcpy( stack[1], temp, sizeof(fp09_double));
184+
memcpy( temp, stack[0], sizeof(Float));
185+
memcpy( stack[0], stack[1], sizeof(Float));
186+
memcpy( stack[1], temp, sizeof(Float));
176187
}
177188
else if( x=='Q' )
178189
{
@@ -238,13 +249,13 @@ void trap_6839()
238249
printf( "trap: %d\n", trap_type );
239250
}
240251

241-
void print_double( fp09_double *d )
252+
void print_float( Float *d )
242253
{
243254
byte c;
244255

245256
fp09_bcd result;
246257
memset( &result, 0, sizeof(fp09_bcd) );
247-
fp09_FPCB cb = {fp09_double_type, 0, 0, 0, trap_6839};
258+
fp09_FPCB cb = {FLOAT_TYPE_ID, 0, 0, 0, trap_6839};
248259
fp09_BINDEC( &cb, 19, d, &result );
249260

250261

@@ -323,7 +334,7 @@ void print_double( fp09_double *d )
323334

324335
void stack_input_buffer()
325336
{
326-
fp09_double result;
337+
Float result;
327338
sbyte i;
328339
byte c;
329340
// fp09_bcd bcd = {0,{0,0,0,0},0x00,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},0};
@@ -358,10 +369,10 @@ void stack_input_buffer()
358369
// shift stack down
359370
for( i=7; i>-1; i-- )
360371
{
361-
memcpy(stack[i+1], stack[i], 8);
372+
memcpy(stack[i+1], stack[i], sizeof(Float));
362373
}
363374

364-
memcpy(stack[0], result, 8);
375+
memcpy(stack[0], result, sizeof(Float));
365376

366377
// blank input buffer
367378
blank = TRUE;
@@ -389,7 +400,7 @@ void draw_stack()
389400
for(c=0; c<8; c++ )
390401
{
391402
locate( 0, c+3 );
392-
print_double( stack[c] );
403+
print_float( stack[c] );
393404
}
394405
}
395406

@@ -401,10 +412,10 @@ void move_stack_up()
401412
// shift stack up
402413
for( c=1; c<7; c++ )
403414
{
404-
memcpy(stack[c], stack[c+1], 8);
415+
memcpy(stack[c], stack[c+1], sizeof(Float));
405416
}
406417

407-
memset( stack[7], 0, 8 );
418+
memset( stack[7], 0, sizeof(Float) );
408419
}
409420

410421
void check_error( fp09_FPCB *cb )

rpn.dsk

Lines changed: 57 additions & 55 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)