git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/include/asm/mos6502/stdlib.h

      1 /** file stdlib.h
      2     'Standard library' functions, for whatever that means.
      3 */
      4 #ifndef STDLIB_INCLUDE
      5 #define STDLIB_INCLUDE
      6 
      7 #include <types.h>
      8 
      9 /** Causes normal program termination and the value of status is
     10     returned to the parent.
     11     All open streams are flushed and closed.
     12 */
     13 void exit(int status);
     14 
     15 #if 0
     16 /** Compatibility function.  Not implemented.
     17  */
     18 int getkey(void);
     19 #endif
     20 
     21 /** Returns the absolute value of int __i__
     22     @param i   Int to obtain absolute value of
     23 
     24     If i is negative, returns -i; else returns i.
     25 */
     26 int abs(int i);
     27 
     28 
     29 /** Returns the absolute value of long int __num__
     30 
     31     @param num   Long integer to obtain absolute value of
     32  */
     33 long labs(long num);
     34 
     35 
     36 /** Converts an ASCII string to an int
     37 
     38     @param s    String to convert to an int
     39 
     40     The string may be of the format
     41     \code{.c}
     42      [\s]*[+-][\d]+[\D]*
     43      \endcode
     44     i.e. any number of spaces, an optional + or -, then an
     45     arbitrary number of digits.
     46 
     47     The result is undefined if the number doesnt fit in an int.
     48 
     49     Returns: Int value of string
     50  */
     51 int atoi(const char *s);
     52 
     53 
     54 /** Converts an ASCII string to a long.
     55     @param s    String to convert to an long int
     56     @see atoi()
     57 
     58     Returns: Long int value of string
     59  */
     60 long atol(const char *s);
     61 
     62 /** Converts an int into a base 10 ASCII string.
     63     @param n      Int to convert to a string
     64     @param s      String to store the converted number
     65     @param radix  Numerical base for converted number, ex: 10 is decimal base
     66                   (parameter is required but not utilized on Game Boy and Analogue Pocket)
     67 
     68     Can be used with @ref set_bkg_based_tiles() for printing if
     69     the digit character tiles are not ascii-mapped.
     70 
     71     Returns:    Pointer to converted string
     72  */
     73 char *itoa(int n, char *s, unsigned char radix);
     74 
     75 /** Converts an unsigned int into a base 10 ASCII string.
     76     @param n      Unsigned Int to convert to a string
     77     @param s      String to store the converted number
     78     @param radix  Numerical base for converted number, ex: 10 is decimal base
     79                   (parameter is required but not utilized on Game Boy and Analogue Pocket)
     80 
     81     Can be used with @ref set_bkg_based_tiles() for printing if
     82     the digit character tiles are not ascii-mapped.
     83 
     84     Returns:    Pointer to converted string
     85  */
     86 char *uitoa(unsigned int n, char *s, unsigned char radix);
     87 
     88 /** Converts a long into a base 10 ASCII string.
     89     @param n      Long int to convert to a string
     90     @param s      String to store the converted number
     91     @param radix  Numerical base for converted number, ex: 10 is decimal base
     92                   (parameter is required but not utilized on Game Boy and Analogue Pocket)
     93 
     94     Can be used with @ref set_bkg_based_tiles() for printing if
     95     the digit character tiles are not ascii-mapped.
     96 
     97     Returns:    Pointer to converted string
     98  */
     99 char *ltoa(long n, char *s, unsigned char radix);
    100 
    101 /** Converts an unsigned long into a base 10 ASCII string.
    102     @param n      Unsigned Long Int to convert to a string
    103     @param s      String to store the converted number
    104     @param radix  Numerical base for converted number, ex: 10 is decimal base
    105                   (parameter is required but not utilized on Game Boy and Analogue Pocket)
    106 
    107     Can be used with @ref set_bkg_based_tiles() for printing if
    108     the digit character tiles are not ascii-mapped.
    109 
    110     Returns:    Pointer to converted string
    111  */
    112 char *ultoa(unsigned long n, char *s, unsigned char radix);
    113 
    114 
    115 /** Memory allocation functions
    116  */
    117 void *calloc (size_t nmemb, size_t size);
    118 void *malloc (size_t size);
    119 void *realloc (void *ptr, size_t size);
    120 #if __STDC_VERSION__ >= 201112L
    121 inline void *aligned_alloc(size_t alignment, size_t size)
    122 {
    123   (void)alignment;
    124   return malloc(size);
    125 }
    126 #endif
    127 extern void free (void * ptr);
    128 
    129 /* Searching and sorting utilities (ISO C11 7.22.5) */
    130 /** search a sorted array of __nmemb__ items
    131     @param key      Pointer to object that is the key for the search
    132     @param base     Pointer to first object in the array to search
    133     @param nmemb    Number of elements in the array
    134     @param size     Size in bytes of each element in the array
    135     @param compar   Function used to compare two elements of the array
    136 
    137     Returns: Pointer to array entry that matches the search key.
    138              If key is not found, NULL is returned.
    139 */
    140 extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) REENTRANT);
    141 
    142 
    143 /** Sort an array of __nmemb__ items
    144     @param base     Pointer to first object in the array to sort
    145     @param nmemb    Number of elements in the array
    146     @param size     Size in bytes of each element in the array
    147     @param compar   Function used to compare and sort two elements of the array
    148 */
    149 extern void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) REENTRANT);
    150 
    151 #endif

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.