{"id":429,"date":"2021-08-19T10:36:31","date_gmt":"2021-08-19T08:36:31","guid":{"rendered":"https:\/\/automatico.freevar.com\/?page_id=429"},"modified":"2021-09-28T17:53:14","modified_gmt":"2021-09-28T15:53:14","slug":"libv","status":"publish","type":"page","link":"https:\/\/automatico.freevar.com\/index.php\/cp-m-80-2\/hitech-c-per-z80\/librerie\/libv\/","title":{"rendered":"LIBV"},"content":{"rendered":"<p><span style=\"font-size: 14pt;\">This library collects the invocations to functions that are not present in Hi-tech C 3.09 which I believe are important.<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">Below are the individual modules to be filled in individually and then linked in the LIBV.LIB library<\/span><\/p>\n<p><span style=\"font-size: 14pt;\"><span class=\"\">I wrote a version of the FMOD module in assembler z80 which you will find at this address<\/span> <a href=\"https:\/\/automatico.freevar.com\/index.php\/cp-m-80-2\/hitech-c-per-z80\/passaggio-parametri\/2\">https:\/\/automatico.freevar.com\/index.php\/cp-m-80-2\/hitech-c-per-z80\/passaggio-parametri\/2<\/a><\/span><\/p>\n<pre class=\"brush: cpp; title: exp.c; notranslate\" title=\"exp.c\">\r\n\/* exp.c *\/\r\n\/* questa funzione rende disponibile anche la funzione &quot;pow&quot; \r\n   con floating point elevato a floating point *\/\r\n#include        &lt;math.h&gt;\r\n\r\nextern double   eval_poly();\r\ndouble\r\nexp(x)\r\ndouble x;\r\n{\r\n        int     exp;\r\n        char    sign;\r\n\r\n        static double coeff&#x5B;] =\r\n        {\r\n                1.0000000000e+00,\r\n                6.9314718056e-01,\r\n                2.4022650695e-01,\r\n                5.5504108945e-02,\r\n                9.6181261779e-03,\r\n                1.3333710529e-03,\r\n                1.5399104432e-04,\r\n                1.5327675257e-05,\r\n                1.2485143336e-06,\r\n                1.3908092221e-07,\r\n        };\r\n\r\n        if(x == 0.0)\r\n                return 1.0;\r\n        sign = x &lt; 0.0;\r\n        if(sign)\r\n                x = -x;\r\n        x *= 1.4426950409;              \/* convert to log2 *\/\r\n        exp = (int)floor(x);\r\n        x -= (double)exp;\r\n        x = ldexp(eval_poly(x, coeff, sizeof coeff\/sizeof coeff&#x5B;0] - 1), exp);\r\n        if(sign)\r\n                return 1.0\/x;\r\n        return x;\r\n}\r\n\r\ndouble\r\npow(x, y)\r\ndouble  x, y;\r\n{\r\n        if(y == 0.0)\r\n                return 1.0;\r\n        if(x &lt; 0.0)\r\n                return 0.0;\r\n        if(x == 0.0)\r\n                return 0.0;\r\n        x = exp(log(x) * y);\r\n        return x;\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: floor.c; notranslate\" title=\"floor.c\">\r\n\/* floor.c *\/\r\n\/* La funzione floor restituisce un valore floating point che rappresenta \r\n   il numero intero pi\u00f9 grande ma minore o uguale a quello passato.\r\n   Non restituisce alcun errore.\r\n*\/\r\n#include        &lt;math.h&gt;\r\n\r\nextern double   _frndint();\r\n\r\ndouble\r\nfloor(x)\r\ndouble  x;\r\n{\r\n        double  i;\r\n\r\n        i = _frndint(x);\r\n        if(i &gt; x)\r\n                return i - 1.0;\r\n        return i;\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: fmod.c; notranslate\" title=\"fmod.c\">\r\n\/* fmod.c *\/\r\n#include &lt;math.h&gt;\r\n#include &lt;float.h&gt;\r\n\/* calcolo del resto della divisione di due numeri in floating point *\/\r\n\r\ndouble\r\nfmod(x, y)\r\ndouble x, y;\r\n{\r\n\/* resto in floating point                      *\/\r\n        double mod;\r\n\r\n\/* se il divisore vale zero la divisione vale infinito *\/\r\n\/* il massimo valore esprimibile in floating point si ritiene\r\n   che sia un valore infinito. In Hi-tech c per Z80 vale 1.84467e19\r\n        if (y == 0.0)\r\n        {\r\n                return FLT_MAX;\r\n        }\r\n\r\n\/* se il dividendo vale zero allora il resto vale zero *\/\r\n        if (x == 0.0)\r\n        {\r\n                return 0.0;\r\n        }\r\n\r\n\/* se il dividendo e\u2019 negativo il valore iniziale del modulo vale il dividendo ma positivo *\/\r\n        if (x &lt; 0.0)\r\n        {\r\n                mod=-x;\r\n        }\r\n\r\n\/* altrimenti il valore del modulo iniziale vale il dividendo *\/\r\n        else\r\n        {\r\n                mod = x;\r\n        }\r\n\r\n\/* se il divisore e\u2019 negativo diventa positivo  *\/\r\n        if (y &lt; 0.0)\r\n        {\r\n                y = -y;\r\n        }\r\n\r\n\/* sottrai il divisore da mod fino a che il resto sia positivo *\/\r\n        while(mod &gt;= y)\r\n        {\r\n                mod = mod \u2013 y;\r\n        }\r\n\r\n\/* se il dividendo e\u2019 negativo allora lo e\u2019 anche il modulo *\/\r\n        if (x &lt; 0.0)\r\n        {\r\n                return -mod;\r\n        }\r\n\r\n        return mod;\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: itoa.c; notranslate\" title=\"itoa.c\">\r\n\/* itoa.c *\/\r\n\/* Una delle funzioni pi\u00f9 importanti, la conversione di un numero\r\n   interno di base assegnata in caratteri ASCII *\/\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\n\/*\r\n        numero = valore intero da convertire\r\n        stringa = buffer di appoggio per il ritorno\r\n        base = base numerica alla quale convertire numero\r\n*\/\r\n\r\nchar*\r\nitoa(numero, stringa, base)\r\nint numero; char* stringa; int base;\r\n{\r\n        int i, j, k;\r\n        char c;\r\n        short unsigned int negativo = 0;\r\n\r\n        \/*\r\n           se numero e' uguale a zero\r\n           riempe il vettore di '0' piu' il terminatore\r\n        *\/\r\n        i = 0;\r\n        if (numero == 0)\r\n        {\r\n                stringa&#x5B;i++] = '0';\r\n                stringa&#x5B;i] = '&#92;&#48;';\r\n                return stringa;\r\n        }\r\n\r\n        \/*\r\n           itoa() standard tratta i numeri negativi solo se\r\n           sono in base 10. Altrimenti i numeri sono considerati\r\n           senza segno.\r\n        *\/\r\n        if (numero &lt; 0 &amp;amp;&amp;amp; base == 10)\r\n        {\r\n                negativo = 1;\r\n                numero = -numero;\r\n        }\r\n\r\n        \/* Scansione del numero in singoli valori               *\/\r\n        while (numero != 0)\r\n        {\r\n                int resto = numero % base;\r\n                stringa&#x5B;i++] = (resto &gt; 9)? (resto-10) + 'a' : resto + '0';\r\n                numero = numero\/base;\r\n        }\r\n\r\n        \/* Se il numero e' negativo aggiungi '-'                *\/\r\n        if (negativo)\r\n                stringa&#x5B;i++] = '-';\r\n\r\n        \/* Aggiunge il terminatore di stringa                   *\/\r\n        stringa&#x5B;i] = '&#92;&#48;';\r\n\r\n        \/* Lunghezza stringa                                    *\/\r\n        i--;\r\n\r\n        \/* Inverte l'ordine degli elementi del vettore          *\/\r\n        for (k = 0, j = i; k&lt;j; k++, j--)\r\n        {\r\n                c = stringa&#x5B;k];\r\n                stringa&#x5B;k] = stringa&#x5B;j];\r\n        }\r\n        return stringa;\r\n}\r\n<\/pre>\n<pre><\/pre>\n<pre class=\"brush: cpp; title: ldexp.c; notranslate\" title=\"ldexp.c\">\r\n\/* ldexp.c *\/\r\n\/* Ritorna il valore di x*2^y  *\/\r\n#include &lt;math.h&gt;\r\n\r\nextern double exp();\r\n\r\ndouble\r\nldexp(x, y)\r\ndouble  x;\r\nint y;\r\n{\r\n        if(y == 0)\r\n                return 1.0;\r\n        if(x == 0.0)\r\n                return 0.0;\r\n        if (x &lt; 0)\r\n        {\r\n                x = -x;\r\n                return -exp(log(x) * y);\r\n        }\r\n        return exp(log(x) * y);\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: logn.c; notranslate\" title=\"logn.c\">\r\n\/* logn.c *\/\r\n\/* Ritorna il logaritmo di val in base passati come parametri *\/\r\n#include &lt;math.h&gt;\r\n#include &quot;float.h&quot;\r\n\r\ndouble\r\nlogn(base, val)\r\nint base;\r\ndouble val;\r\n{\r\n        return log(val)\/log(base);\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: power.c; notranslate\" title=\"power.c\">\r\n\/* power.c *\/\r\n#include  &lt;math.h&gt;\r\n\r\nextern double exp();\r\n\r\ndouble\r\npower(x, y)\r\ndouble  x, y;\r\n{\r\n        if(y == 0.0)\r\n                return 1.0;\r\n\r\n        if(x == 0.0)\r\n                return 0.0;\r\n\r\n        if (x &lt; 0)\r\n        {\r\n                x = -x;\r\n                return -exp(log(x) * y);\r\n        }\r\n\r\n        return exp(log(x) * y);\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: radcub.c; notranslate\" title=\"radcub.c\">\r\n\/* radcub.c *\/\r\n#include &lt;math.h&gt;\r\n\r\nextern double pow(double,double);\r\n\r\ndouble radcub(r)\r\ndouble r;\r\n{\r\n        double y;\r\n        y = pow(r, 0.3333333);\r\n        return y;\r\n}\r\n<\/pre>\n<p><span style=\"font-size: 14pt;\">Per facilitare il compito di costruzione della libreria ecco le direttive di compilazione in forma SUBMIT:<\/span><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n;----------  LIBV.SUB  ----------\r\nc -C -O EXP.C\r\nc -C -O FLOOR.C\r\nc -C -O ITOA.C\r\nc -C -O LDEXP.C\r\nc -C -O LOGN.C\r\nc -C -O POWER.C\r\nc -C -O RADCUB.C\r\nc -C -O FMOD.C\r\nLIBR R LIBV.LIB EXP.OBJ\r\nLIBR R LIBV.LIB FLOOR.OBJ\r\nLIBR R LIBV.LIB ITOA.OBJ\r\nLIBR R LIBV.LIB LOGN.OBJ\r\nLIBR R LIBV.LIB POWER.OBJ\r\nLIBR R LIBV.LIB RADCUB.OBJ\r\nLIBR R LIBV.LIB FMOD.OBJ\r\n;----------  fine  ----------\r\nLIBR M LIBV.LIB\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_429\" class=\"pvc_stats all  \" data-element-id=\"429\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This library collects the invocations to functions that are not present in Hi-tech C 3.09 which I believe are important. Below are the individual modules to be filled in individually and then linked in the LIBV.LIB library I wrote a version of the FMOD module in assembler z80 which you will find at this address [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_429\" class=\"pvc_stats all  \" data-element-id=\"429\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"parent":92,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-429","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/429"}],"collection":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":14,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/429\/revisions"}],"predecessor-version":[{"id":767,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/429\/revisions\/767"}],"up":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/92"}],"wp:attachment":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/media?parent=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}