Mercurial > hg > Members > kono > os9 > sbc09
comparison basic/makeflot.c @ 57:2088fd998865
sbc09 directry clean up
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Jul 2018 16:07:12 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
56:4fa2bdb0c457 | 57:2088fd998865 |
---|---|
1 /* This program converts floating point numbers to | |
2 the 5-bit binary representation used in 6809 BASIC. | |
3 */ | |
4 | |
5 #include <stdlib.h> | |
6 #include <stdio.h> | |
7 #include <math.h> | |
8 #include <ctype.h> | |
9 #include <string.h> | |
10 | |
11 main() | |
12 { | |
13 double num; | |
14 char line[128],label[128]; | |
15 unsigned char byte[5]; | |
16 int expo,sign,i; | |
17 unsigned long mant; | |
18 label[0]=0; | |
19 printf("* These are the floating point constants.\n"); | |
20 printf("* They are generated by the program makeflot.c\n"); | |
21 while(fgets(line,128,stdin)) { | |
22 line[strlen(line)-1]=0; | |
23 if(!line[0])continue; | |
24 if(line[0]=='*'){printf("%s\n",line);continue;} | |
25 if(isalpha(line[0])) { | |
26 sscanf(line,"%s",label); | |
27 }else{ | |
28 sscanf(line,"%lf",&num); | |
29 if(num==0) { | |
30 sign=0; | |
31 expo=0; | |
32 mant=0; | |
33 }else{ | |
34 sign=0x80*(num<0); | |
35 num=fabs(num); | |
36 expo=0x9f; | |
37 while(num<2147483648.0){ | |
38 num=num*2; | |
39 expo-=1; | |
40 } | |
41 while(num>=4294967296.0){ | |
42 num=num/2; | |
43 expo+=1; | |
44 } | |
45 mant=num+0.5; | |
46 } | |
47 byte[0]=expo;byte[1]=((mant>>24)&0x7f)+sign; | |
48 byte[2]=((mant>>16)&0xff);byte[3]=((mant>>8)&0xff);byte[4]=mant&0xff; | |
49 printf("%-16s fcb $%02x,$%02x,$%02x,$%02x,$%02x ;%s\n", | |
50 label,byte[0],byte[1],byte[2],byte[3],byte[4],line); | |
51 label[0]=0; | |
52 } | |
53 } | |
54 printf("* End of floating point constants.\n"); | |
55 exit(0); | |
56 } |