project_files/hwc/rtl/system.c
changeset 16018 692903667ece
parent 14249 06f2dc4deab2
equal deleted inserted replaced
16017:e8afb1bf2779 16018:692903667ece
   213 
   213 
   214 }
   214 }
   215 
   215 
   216 string255 fpcrtl_floatToStr(double n) {
   216 string255 fpcrtl_floatToStr(double n) {
   217     string255 t;
   217     string255 t;
   218     sprintf(t.str, "%f", n);
   218     
   219     t.len = strlen(t.str);
   219     t.len = sprintf(t.str, "%f", n);
   220 
   220 
   221     return t;
   221     return t;
   222 }
   222 }
   223 
   223 
   224 void fpcrtl_move__vars(void *src, void *dst, SizeInt count) {
   224 void fpcrtl_move__vars(void *src, void *dst, SizeInt count) {
   350 }
   350 }
   351 
   351 
   352 LongInt str_to_int(char *src)
   352 LongInt str_to_int(char *src)
   353 {
   353 {
   354     int i;
   354     int i;
   355     int len = strlen(src);
       
   356     char *end;
   355     char *end;
   357     for(i = 0; i < len; i++)
   356     for(i = 0; src[i]; i++)
   358     {
   357     {
   359         if(src[i] == '$'){
   358         if(src[i] == '$'){
   360             // hex
   359             // hex
   361             return strtol(src + i + 1, &end, 16);
   360             return strtol(src + i + 1, &end, 16);
   362         }
   361         }
   385 }
   384 }
   386 
   385 
   387 LongInt fpcrtl_random(LongInt l) {
   386 LongInt fpcrtl_random(LongInt l) {
   388     // random(0) is undefined in docs but effectively returns 0 in free pascal
   387     // random(0) is undefined in docs but effectively returns 0 in free pascal
   389     if (l == 0) {
   388     if (l == 0) {
   390         printf("WARNING: random(0) called!\n");
   389         //printf("WARNING: random(0) called!\n");
   391         return 0;
   390         return 0;
   392     }
   391     }
   393     return (LongInt) (rand() / (double) RAND_MAX * l);
   392     return (LongInt) (rand() / (double) RAND_MAX * l);
   394 }
   393 }
   395 
   394 
   396 void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) {
   395 void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) {
   397     sprintf(s->str, "%f", x);
   396     s->len = sprintf(s->str, "%f", x);
   398     s->len = strlen(s->str);
       
   399 }
   397 }
   400 void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) {
   398 void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) {
   401     sprintf(s->str, "%f", x);
   399     s->len = sprintf(s->str, "%f", x);
   402     s->len = strlen(s->str);
       
   403 }
   400 }
   404 void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) {
   401 void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) {
   405     sprintf(s->str, "%u", x);
   402     s->len = sprintf(s->str, "%u", x);
   406     s->len = strlen(s->str);
       
   407 }
   403 }
   408 void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) {
   404 void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) {
   409     sprintf(s->str, "%d", x);
   405     s->len = sprintf(s->str, "%d", x);
   410     s->len = strlen(s->str);
       
   411 }
   406 }
   412 void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) {
   407 void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) {
   413     sprintf(s->str, "%u", x);
   408     s->len = sprintf(s->str, "%u", x);
   414     s->len = strlen(s->str);
       
   415 }
   409 }
   416 void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) {
   410 void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) {
   417     sprintf(s->str, "%d", x);
   411     s->len = sprintf(s->str, "%d", x);
   418     s->len = strlen(s->str);
       
   419 }
   412 }
   420 void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) {
   413 void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) {
   421     sprintf(s->str, "%u", x);
   414     s->len = sprintf(s->str, "%u", x);
   422     s->len = strlen(s->str);
       
   423 }
   415 }
   424 void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) {
   416 void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) {
   425     sprintf(s->str, "%d", x);
   417     s->len = sprintf(s->str, "%d", x);
   426     s->len = strlen(s->str);
       
   427 }
   418 }
   428 void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) {
   419 void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) {
   429     sprintf(s->str, "%llu", x);
   420     s->len = sprintf(s->str, "%llu", x);
   430     s->len = strlen(s->str);
       
   431 }
   421 }
   432 void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) {
   422 void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) {
   433     sprintf(s->str, "%lld", x);
   423     s->len = sprintf(s->str, "%lld", x);
   434     s->len = strlen(s->str);
       
   435 }
   424 }
   436 
   425 
   437 /*
   426 /*
   438  * XXX No protection currently!
   427  * XXX No protection currently!
   439  */
   428  */