Mercurial > hg > Members > kono > os9 > sbc09
view basic/makeflot.c @ 162:d3a9f5f7befb
fix TL1 PIC
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Apr 2019 22:49:44 +0900 |
parents | 2088fd998865 |
children |
line wrap: on
line source
/* This program converts floating point numbers to the 5-bit binary representation used in 6809 BASIC. */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <ctype.h> #include <string.h> main() { double num; char line[128],label[128]; unsigned char byte[5]; int expo,sign,i; unsigned long mant; label[0]=0; printf("* These are the floating point constants.\n"); printf("* They are generated by the program makeflot.c\n"); while(fgets(line,128,stdin)) { line[strlen(line)-1]=0; if(!line[0])continue; if(line[0]=='*'){printf("%s\n",line);continue;} if(isalpha(line[0])) { sscanf(line,"%s",label); }else{ sscanf(line,"%lf",&num); if(num==0) { sign=0; expo=0; mant=0; }else{ sign=0x80*(num<0); num=fabs(num); expo=0x9f; while(num<2147483648.0){ num=num*2; expo-=1; } while(num>=4294967296.0){ num=num/2; expo+=1; } mant=num+0.5; } byte[0]=expo;byte[1]=((mant>>24)&0x7f)+sign; byte[2]=((mant>>16)&0xff);byte[3]=((mant>>8)&0xff);byte[4]=mant&0xff; printf("%-16s fcb $%02x,$%02x,$%02x,$%02x,$%02x ;%s\n", label,byte[0],byte[1],byte[2],byte[3],byte[4],line); label[0]=0; } } printf("* End of floating point constants.\n"); exit(0); }