home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d130
/
hp.lha
/
Hp
/
hp_conversions.include
< prev
next >
Wrap
Text File
|
1988-03-13
|
8KB
|
335 lines
/*-------------------------------------------*/
/* */
/* Filename: hp_conversions.include */
/* */
/* Contains the C source code for the */
/* routines DisplayFloatXY, DisplayIntXY, */
/* InkeyIsNumeric, ContinueNumEntry, */
/* CommenceNumEntry and PushX. These */
/* are used by the routine hp.c. */
/* */
/*-------------------------------------------*/
DisplayFloatXY()
{
int i, xpoint, xsign, ypoint, ysign;
char temp_string[34], *tsptr;
xptr = &xstr[9];
yptr = &ystr[9];
tsptr = &temp_string[9];
/* Convert floating point to ASCII */
tsptr = ecvt( x, 12, &xpoint, &xsign );
for ( i = 20; i >= 10; i--) xstr[i+1] = *(tsptr + i - 9);
xstr[9] = *tsptr;
tsptr = ecvt( y, 12, &ypoint, &ysign );
for ( i = 20; i >= 10; i--) ystr[i+1] = *(tsptr + i - 9);
ystr[9] = *tsptr;
/* Prevents the display of 0.0 E-1 */
if ( x == 0.0 ) {
xpoint = 1 ;
xstr[9] = '0'; }
if ( y == 0.0 ) {
ypoint = 1 ;
ystr[9] = '0'; }
xstr[22] = ' ';
ystr[22] = ' ';
xstr[23] = ' ';
ystr[23] = ' ';
xstr[10] = '.';
ystr[10] = '.';
xstr[ 8] = ' ';
ystr[ 8] = ' ';
if ( xsign != 0 ) xstr[8] = '-';
if ( ysign != 0 ) ystr[8] = '-';
if ( xpoint < 1 )
xstr[24] = '-';
else
xstr[24] = ' ';
xpoint = abs( xpoint - 1 );
xstr[25] = hex_char[ xpoint / 10 ];
xstr[26] = hex_char[ xpoint % 10 ];
xstr[27] = 0;
if ( ypoint < 1 )
ystr[24] = '-';
else
ystr[24] = ' ';
ypoint = abs( ypoint - 1 );
ystr[25] = hex_char[ ypoint / 10 ];
ystr[26] = hex_char[ ypoint % 10 ];
ystr[27] = 0;
SetAPen( rp, BLACK );
SetDrMd( rp, JAM2 );
Move( rp, start_display[ base ], 50);
Text( rp, &ystr[8], 19 );
Move( rp, start_display[ base ], 59);
Text( rp, &xstr[8], 19 );
}
/*--------------------------------------------------------*/
DisplayIntXY()
{
unsigned long tempint;
int j, numbits, next_digit, x_length, y_length, x_shift, y_shift;
if ( base == 10 ) {
x_length = stci_d( &xstr[0], ix, 12 );
y_length = stci_d( &ystr[0], iy, 12 );
xstr[display_length[10]] = 0;
ystr[display_length[10]] = 0;
x_shift = display_length[10] - x_length;
y_shift = display_length[10] - y_length;
for( j = x_length-1; j >= 0; j--)
xstr[j + x_shift] = xstr[j];
for( j = y_length-1; j >= 0; j--)
ystr[j + y_shift] = ystr[j];
for( j = x_shift-1; j >= 0; j--)
xstr[j] = ' ';
for( j = y_shift-1; j >= 0; j--)
ystr[j] = ' ';
}
else { /* Base is power of two */
if ( base == 2 ) numbits = 1;
if ( base == 8 ) numbits = 3;
if ( base == 16 ) numbits = 4;
xstr[ display_length[ base ] ] = 0;
j = display_length[ base ] - 1;
tempint = ix;
while ( tempint != 0 ) {
next_digit = tempint & bitmask[ numbits ];
xstr[ j-- ] = hex_char[ next_digit ];
tempint >>= numbits; }
if ( ix == 0 ) xstr[j--] = '0';
while ( j >= 0 ) xstr[j--] = ' ';
/* Now repeat the process for y */
ystr[ display_length[ base ] ] = 0;
j = display_length[ base ] - 1;
tempint = iy;
while ( tempint != 0 ) {
next_digit = tempint & bitmask[ numbits ];
ystr[ j-- ] = hex_char[ next_digit ];
tempint >>= numbits; }
if ( iy == 0 ) ystr[j--] = '0';
while ( j >= 0 ) ystr[j--] = ' ';
} /* Base is power of 2 */
Move( rp, start_display[ base ], 50);
Text( rp, &ystr[0], display_length[ base ] );
Move( rp, start_display[ base ], 59);
Text( rp, &xstr[0], display_length[ base ] );
}
/*--------------------------------------------------------*/
BOOL InkeyIsNumeric()
{
int k;
if ( inkey == 16 ) return( TRUE );
if ( (inkey == 53 ) && (base > 1) ) return( FALSE );
if ( (inkey == 53 ) && (entry_in_progress == FALSE)) return( FALSE );
k = inkey % 4;
if ( (inkey > 0) && (inkey < 19) && (k != 0) ) return( TRUE );
if ( (inkey == 49) || (inkey == 50) ) return( TRUE );
if ( (inkey == 53) || (inkey == 54) ) return( TRUE );
return( FALSE );
}
/*--------------------------------------------------------*/
ContinueNumEntry()
{
int signif_length, flip_pos;
char flip_val;
lastbase = base;
if (base < 2) {
if ( (exponent_entered) || (inkey == 54) )
signif_length = 19;
else
signif_length = 14; }
else
signif_length = display_length[ base ];
if ( (next_digit >= signif_length) && (inkey != 53) ) {
BeepHpDisplay();
return( 0 ); }
if ((inkey == 50) && decimal_entered) {
BeepHpDisplay();
return(0); }
if ( inkey == 50 ) decimal_entered = TRUE;
if ( (inkey == 53) || (inkey == 54) ) {
/* CHS key has been struck */
if ( inkey == 53 ) {
if ( exponent_entered ) {
flip_pos = 16;
flip_val = instring[16]; }
else {
flip_pos = 0;
flip_val = instring[ 0]; }
if ( flip_val == ' ' )
instring[ flip_pos ] = '-';
else
instring[ flip_pos ] = ' '; }
else /* EEX entered */ {
exponent_entered = TRUE;
instring[17] = '_'; /* underscore as prompt */
next_digit = 18; } }
else /* A digit has been struck */
instring[next_digit++] = digit_table[ inkey ];
Move( rp, start_display[base], 59 );
Text( rp, &instring[0], next_digit);
/* Wipe out the exponent prompt character on the next keystroke */
if ( inkey == 54 ) next_digit = 17;
}
/*--------------------------------------------------------*/
CommenceNumEntry()
{
int k, str_offset;
lastbase = base;
entry_in_progress = TRUE;
if ( inkey == 54 )
exponent_entered = TRUE;
else
exponent_entered = FALSE;
if ( inkey == 50 )
decimal_entered = TRUE;
else
decimal_entered = FALSE;
if( base > 1 )
str_offset = 0;
else
str_offset = 8;
/* Move x up to the y position */
Move( rp, start_display[base], 50);
Text( rp, &xstr[str_offset], display_length[base] );
/* Blank out old x register */
Move( rp, start_display[base], 59 );
Text( rp, " ", display_length[base] );
if ( base < 2 ) {
instring[0] = ' ';
for ( k = 2; k < 19; k++) instring[k] = ' ';
if ( inkey == 54 ) {
instring[1] = '1';
instring[17] = '_';
next_digit = 18;
}
else {
instring[ 1] = digit_table[ inkey ];
next_digit = 2; } }
else {
instring[0] = digit_table[ inkey ];
next_digit = 1; }
Move( rp, start_display[base], 59 );
Text( rp, &instring[0], next_digit);
if ( inkey == 54 ) next_digit = 17;
}
/*--------------------------------------------------------------*/
PushX()
{
int k;
if ( base > 1 ) {
it = iz;
iz = iy;
iy = ix;
ix = 0;
/* Convert string to long integer */
for( k = 0; k < next_digit; k++) {
if ( instring[k] > 60 ) instring[k] -= 7;
ix = base * ix + instring[k] - 48; }
}
else { /* Push float or complex component onto stack */
t = z;
z = y;
y = x;
if ( instring[16] == ' ' )
instring[16] = 'e';
else
instring[15] = 'e';
if ( instring[17] == '_' ) instring[17] = ' ';
if ( decimal_entered == FALSE ) {
k = 1;
while ( (instring[k] != ' ') && (k < 14) )
k++;
instring[k] = '.'; }
for ( k = 1; k < 16; k++ ) {
if ( instring[k] == ' ' ) instring[k] = '0'; }
instring[19] = 0;
if (instring[18] == ' ') {
if (instring[17] == ' ')
instring[14] = 0;
else
instring[18] = 0; }
x = atof( &instring[0] ); }
}