sd:list_of_tinyc_built-in_functions
This is an old revision of the document!
Table of Contents
List of TinyC Built-in Functions
- From: TinyC for the SD-8516
For actual built ins I mainly have putchar() and getchar() which use the BASIC IO_ library at INT $05. After that, a lot can be written in C.
Terminal IO
- Builtin: putchar()
- Builtin: getchar()
print()
int print(char *s) {
int i = 0;
while (s[i] != 0) {
putchar(s[i]);
i = i + 1;
}
return 0;
}
println()
int println(char *s) {
print(s);
putchar(13);
putchar(10);
return 0;
}
printnum()
int printnum(int n) {
char *buf = 0xDF00;
int i = 0;
int neg = 0;
if (n < 0) {
neg = 1;
n = 0 - n;
}
if (n == 0) {
putchar('0');
return 0;
}
while (n > 0) {
*(buf + i) = n - (n / 10) * 10 + '0';
n = n / 10;
i = i + 1;
}
if (neg) {
putchar('-');
}
while (i > 0) {
i = i - 1;
putchar(buf[i]);
}
return 0;
}
readline()
int readline(char *buf, int max) {
int i = 0;
int c = 0;
while (i < max - 1) {
c = getchar();
if (c == 13) {
putchar(13);
putchar(10);
*(buf + i) = 0;
return i;
}
if (c == 8) {
if (i > 0) {
i = i - 1;
putchar(8);
putchar(' ');
putchar(8);
}
} else {
*(buf + i) = c;
putchar(c);
i = i + 1;
}
}
*(buf + i) = 0;
return i;
}
Strings stuff
strcmp()
int strcmp(char *a, char *b) {
int i = 0;
while (a[i] != 0) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
i = i + 1;
}
return a[i] - b[i];
}
strlen()
int strlen(char *s) {
int i = 0;
while (s[i] != 0) {
i = i + 1;
}
return i;
}
strcpy()
int strcpy(char *dst, char *src) {
int i = 0;
while (src[i] != 0) {
*(dst + i) = src[i];
i = i + 1;
}
*(dst + i) = 0;
return i;
}
strcat()
int strcat(char *dst, char *src) {
int di = strlen(dst);
int si = 0;
while (src[si] != 0) {
*(dst + di) = src[si];
di = di + 1;
si = si + 1;
}
*(dst + di) = 0;
return di;
}
atoi()
int atoi(char *s) {
int n = 0;
int i = 0;
while (isdigit(s[i])) {
n = n * 10 + s[i] - '0';
i = i + 1;
}
return n;
}
int strncmp(char *a, char *b, int n) {
int i = 0;
while (i < n) {
if (a[i] != b[i]) {
return a[i] - b[i];
}
if (a[i] == 0) { return 0; }
i = i + 1;
}
return 0;
}
int strchr(char *s, int c) {
int i = 0;
while (s[i] != 0) {
if (s[i] == c) { return i; }
i = i + 1;
}
return 0 - 1;
}
int itoa(int n, char *buf) {
int i = 0;
int neg = 0;
if (n < 0) {
neg = 1;
n = 0 - n;
}
if (n == 0) {
*(buf) = '0';
*(buf + 1) = 0;
return 1;
}
char *tmp = 0xDEF0;
while (n > 0) {
*(tmp + i) = n - (n / 10) * 10 + '0';
n = n / 10;
i = i + 1;
}
int j = 0;
if (neg) {
*(buf) = '-';
j = 1;
}
while (i > 0) {
i = i - 1;
*(buf + j) = tmp[i];
j = j + 1;
}
*(buf + j) = 0;
return j;
}
Memory stuff
memset()
int memset(char *p, int val, int len) {
int i = 0;
while (i < len) {
*(p + i) = val;
i = i + 1;
}
return 0;
}
memcpy()
int memcpy(char *dst, char *src, int len) {
int i = 0;
while (i < len) {
*(dst + i) = src[i];
i = i + 1;
}
return 0;
}
Char stuff
isdigit()
int isdigit(int c) {
if (c >= '0') {
if (c <= '9') {
return 1;
}
}
return 0;
}
isalpha()
int isalpha(int c) {
if (c >= 'a') {
if (c <= 'z') {
return 1;
}
}
if (c >= 'A') {
if (c <= 'Z') {
return 1;
}
}
return 0;
}
isspace()
int isspace(int c) {
if (c == ' ') { return 1; }
if (c == 9) { return 1; }
if (c == 10) { return 1; }
if (c == 13) { return 1; }
return 0;
}
isupper()
int isupper(int c) {
if (c >= 'A') {
if (c <= 'Z') {
return 1;
}
}
return 0;
}
islower()
int islower(int c) {
if (c >= 'a') {
if (c <= 'z') {
return 1;
}
}
return 0;
}
toupper()
int toupper(int c) {
if (islower(c)) {
return c - 32;
}
return c;
}
tolower()
int tolower(int c) {
if (isupper(c)) {
return c + 32;
}
return c;
}
Math stuff
abs()
int abs(int n) {
if (n < 0) { return 0 - n; }
return n;
}
min()
int min(int a, int b) {
if (a < b) { return a; }
return b;
}
max()
int max(int a, int b) {
if (a > b) { return a; }
return b;
}
sd/list_of_tinyc_built-in_functions.1776252176.txt.gz · Last modified: by appledog
