Standard I/O Standard I/O

Tos–GNU C Library Functions

This reference card describes the available library functions of GNU C on the Atari ST.

Standard I/O

#include ⟨stdio.h⟩

FILE *fopen ( const char *fname,

const char *mode );

Open file fname with mode mode for stream I/O.

FILE *freopen ( const char *fname,

const char *mode, FILE *fp );

Reopen fp with file fname and mode mode. FILE *fdopen ( int fd, const char *mode );

Connect a filepointer to the filedescriptor fd with mode mode.

int fgetc ( FILE *fp ); Get a character from stream fp.

char *fgets ( char *buf, int max, FILE *fp ); Get a string including the NL character from stream fp with max byte into buf.

char *gets ( char *buf ); Get a string from ⟨stdin⟩ into buf. The NL character is discarded.

int fputc ( int c, FILE *fp ); Write a character c into stream fp.

int fputs ( const char *buf, FILE *fp ); Write the string in buf into stream fp.

int puts ( const char *buf ); Write the string in buf to ⟨stdout⟩ appending a NL character.

int fungetc ( int c, FILE *fp ); Push the character c back onto stream fp. The following aliases for the above functions are defined.

getc  fgetc
ungetc  fungetc
putc  fputc
getchar()  fgetc(stdin)
ungetchar(c)  fungetc((c),stdin)
putchar(c)  fputc((c),stdout)

long getl ( FILE *fp ); Read a long value from stream fp.

long putl ( long c, FILE *fp ); Output the long value c into the stream fp.

short getw ( FILE *fp ); Read a short value from stream fp.

short putw ( short c, FILE *fp ); Output the short value c into the stream fp.

size t fread ( void *buf,

size t sz, size t no, FILE *fp );

Read no items of size sz from stream fp into buf.

size t fwrite ( const void *buf,

size t size, size t no , FILE *fp );

Write no items of size sz from buf into stream fp. int fgetpos ( FILE *fp, fpos t *ptr );

Put the current position of the filepointer of stream fp into the address ptr.

int fsetpos ( FILE *fp, fpos t *ptr ); Set the position of the filepointer of stream fp to the value at address ptr. int fflush ( FILE *fp );

Write data from internal buffer of stream fp to the file. int fclose ( FILE *fp );

Close the stream fp. int printf ( const char *fmt, …); int fprintf ( FILE *fp, const char *fmt, …); int sprintf ( char *buf, const char *fmt, …); int vprintf ( const char *fmt, char * ); int vfprintf ( FILE *fp, const char *fmt, char * ); int vsprintf ( char *buf, const char *fmt, char * );

Formated output to either ⟨stdout⟩, fp or buf with fixed or variable number of arguments.

int scanf ( const char *fmt, …);

int fscanf ( FILE *fp, const char *fmt, …);

int sscanf ( const char *buf, const char *fmt, …); Formated input from either ⟨stdin⟩, fp or buf. The following table lists the identifying letters of the fmt string.

scanf  printf  Meaning
d  d,i  Decimal number
o  o  Octal number
x  x,X  Hexadecimal number
u  u  Unsigned decimal n.
b  Unsigned binary int.
i  Any base num.
D  D  Long Decimal number
O  O  Long Octal number
U  U  Unsigned long decimal
X  Long Hexadecimal
ld,lo,lx ld,li,lo,lx,lX Long … number
lb  Unsigned binary long
li  Any base num. long
hd,ho,hx  d,o,x,X  Short … number
c  c  Character
s  s  String
p  Pointer
[…]  Str. consist. of char.
e,f,g  f  Fixed-point number
e,f,g  e,E  Floating-point number
le,lf,lg  Double prec. … n.
E,F,G  Double prec. … n.
Le,Lf,Lg Le,LE,Lf Long Double … n.
g,G,Lg,LG  e/E or f - shortest used

int fseek ( FILE *fp, long pos, int whence ); Move the the filepointer from stream fp to position pos relative to whence.

long ftell ( FILE *fp ); Get the current position of the filepointer from stream fp.

void rewind ( FILE *fp ); Reset the filepointer from stream fp to position 0. FILE *popen ( const char *command, const char *mode );

Open a pipe with mode to command. (Faked by temporary files) int pclose ( FILE *fp );

Close the stream created by popen(). void setbuf ( FILE *fp, char *buf ); Set buffer of stream fp to buf.

int setvbuf ( FILE *fp, char *buf, int mode, size t sz ); Set buffer of stream fp to buf with size sz and mode mode.

Standard I/O Character Classification and Conversion

void binmode ( int bool ); Set default open mode to binary (bool = true) or text.

int remove ( const char *fname );

Remove file with name fname. int rename ( const char *old, const char *new );

Change name of file from old to new. char *tmpnam ( char *buf );

Create a string for a temporary filename. FILE *tmpfile ( void );

Create a temporary file. File is deleted on normal termination.

void perror ( const char *str ); Display error message starting with str depending on errno.

The following functions are defined as macros. void clearerr ( FILE *fp );

Clear error and EOF status of stream fp. int feof ( FILE *fp );

Test EOF status of stream fp. int ferror ( FILE *fp );

Test error status of stream fp. int fileno ( FILE *fp );

Get filedescriptor of stream fp.

I/O Control

#include ⟨ioctl.h⟩ int ioctl ( int fd, int cmd, void *arg );

Set or inquire i/o dependend parameter. int stty ( int fd, struct sgttyb * tty ); int gtty ( int fd, struct sgttyb * tty );

Set or inquire i/o parameters for descriptor fd.

#include ⟨fcntl.h⟩ int fcntl ( int fd, int cmd, void *arg );

Set or inquire file i/o dependend parameter.

Memory Management

#include ⟨stdlib.h⟩ void *calloc ( size t no, size t sz ); void *clalloc ( long no, long sz );

Allocate and initialize memory for no items of size size. void *malloc ( size t sz ); void *mlalloc ( long sz );

Allocate sz bytes of memory. void *realloc ( void *ptr, size t sz ); void *relalloc ( void *ptr, long sz );

Resize memory pointed to by ptr to size sz. void free ( void *ptr );

Free memory obtained by calloc, malloc or realloc. void *alloca ( size t sz );

Allocate sz bytes from the current function stack. void malloczero ( int bool );

Zero allocated memory blocks. Default==false. void mallocChunkSize ( size t Siz );

Get memory from OS in atleast Siz sized blocks. Default==4K

Character Classification and Conversion

The following functions return ≠ 0, if character c belongs to the specified character set; 0 otherwise. #include ⟨ctype.h⟩

function  set
isalnum(c) Letter or Digit
isalpha(c) Letter
isascii(c)  ASCII character (Codes: 0…0177)
iscntrl(c) Control character (Codes: 0…037, 0177)
isdigit(c) Digit
isgraph(c) Printable character except space
islower(c) Lowercase letter
isprint(c) Printable character
ispunct(c) Punctuation char. (not letter, digit or control)
isspace(c) Space, Tab, CR, NL, VT, FF or BS
isupper(c) Uppercase letter
isxdigit(c) Hexadecimal digit
iswhite(c) same as ispace()
isodigit(c) Octal digit
iscymf(c) Character starting a C identifier
iscym(c)  Characters continuing a C identifier

Character conversion functions

function  Meaning
toupper(c) Convert to uppercase letter
toupper(c) Convert to uppercase letter (macro)
tolower(c) Convert to lowercase letter
tolower(c) Convert to lowercase letter (macro)
toint(c)  Convert digit to integer

String Handling

#include ⟨string.h⟩ char *strcpy ( char *dst, const char *src );

Copy string at src to dst. char *strncpy ( char *dst, const char *src, size t no );

Copy string at src to dst, but at most sl no character. char *strcat ( char *dst, const char *src );

Concatenate the string at src to the string at dst. char *strncat ( char *dst, const char *src, size t no );

Concatenate the string at src to the string at dst, but copy at most no character.

int strcmp ( const char *str1, const char *str2 ); Compare string str1 with string str1.

int strncmp ( const char *str1, const char *str2, size t no ); Compare string str1 with string str1, but compare at most no character.

char *strchr ( const char *str, int charw ); Find first occurence of character charw in string str.

char *strrchr ( const char *str, int charw ); Find last occurence of character charw in string str.

size t strcspn ( const char *str, const char *rej ); Find length of initial segment of str consisting entirely of characters not from rej.

char *strpbrk ( const char *str, const char *breakat ); First occurrence of a character from string breakat in string str.

size t strspn ( const char *str, const char *accept ); Find length of initial segment of str consisting entirely of characters from accept.

String Handling Date and Time

char *strstr ( const char *str, const char *wanted ); Find first occurence of string wanted in string str.

char *strtok ( char *str, const char *delim ); Retrieve fields from string str, that are delimited by characters from string delim.

size t strlen ( const char *str ); Return length of string str.

char *strerror ( int errno ); Map error number errno to descriptive string.

char *strlwr ( char *str ); Change all character from string str to lowercase.

char *strrev ( char *str ); Reverse all charcters in string str. First character becomes last character.

char *strdup ( const char *str ); Return a duplicate of string str.

int memcmp ( const void *ptr1,

const void *ptr2, size t no );

Compare no bytes from memory area at ptr1 with area at ptr2.

void *memset ( void *ptr, int ucharfill, size t no ); Set no of bytes at position ptr to character ucharfill.

void *memchr ( const void *ptr,

int ucharwanted, size t no );

Find character ucharwanted in area at ptr, but compare at most no character.

void *memcpy ( void *dst, const void *src, size t no ); Copy no of bytes from area at src to dst.

void *memccpy ( void *dst,

const void *src, int ucharstop, size t no );

Copy characters from src to dst until character ucharstop, but copy at most no bytes.

char *index ( const char *str, int charw );

Same as strchr. char *rindex ( const char *str, int charw );

Same as strrchr. void bcopy ( const void *src, void *dst, size t len );

Copy len bytes from position src to dst. int bcmp ( const void *ptr1, const void *ptr2, size t no );

Compare no of bytes at position ptr1 with ptr2. void bzero ( void *dst, size t len );

Set len bytes at position dst to 0.

Process Management

#include ⟨stdlib.h⟩ int system ( const char *prog );

Execute command prog passed as a string.

#include ⟨process.h⟩ int spawnl ( int mode, char *path, …); int spawnv ( int mode, char *path, char **argv ); int spawnle ( int mode, char *path, …);

int spawnve ( int mode, char *path,

char **argv, char **envp );

Spawn a new process. (Only P WAIT is allowed for mode). int spawnvp ( int mode, char *name, char **argv ); int spawnlp ( int mode, char *name, …);

Execute a program on the defautl system execution path. (The current directory is always searched first.)

Date and Time

#include ⟨time.h⟩

clock t clock ( ); Return process time used so far in units of CLK TCK ticks per second (under TOS, 200 per second).

double difftime ( time t t1, time t t2 ); Return difference between two “time t” types.

time t mktime ( const struct tm *t ); Take a time structure and convert it into representation “seconds since midnight January 1 1970, GMT”.

time t time ( time t *t ); Return time in seconds since midnight January 1 1970, GMT.

char *asctime ( const struct tm *t ); Convert “time” structure to a string.

char *ctime ( const time t *t ); Convert time in seconds since 1970 to a string.

struct tm *gmtime ( const time t *t );

Get the Greenwich Mean time. struct tm *localtime ( const time t *t );

Convert given time in seconds since 1970 to local time.

size t strftime ( char *s, size t maxsize, const char *format,

const struct tm *timeptr );

Print formatted information about a given time. void tzset ( );

Set the timezone and dst flag to the local rules (depending on environment variable “TZ”).

File and Directory Information

#include ⟨types.h⟩

#include ⟨stat.h⟩

int stat ( const char *fname, struct stat *info );

Obtain information about file fname. int lstat ( const char *fname, struct stat *info );

Like stat but return info about symbolic links. int fstat ( int fd, struct stat *info );

Obtain information about file assosiated with filedescriptor fd.

#include ⟨dirent.h⟩

DIR *opendir ( const char *dirname ); Open directory dirname for reading.

struct dirent *readdir ( DIR *dirp ); Read an entry from directory assosiated with dirp.

off t telldir ( DIR *dirp ); Get the current position in directory assosiated with dirp.

void seekdir ( DIR *dirp, off t loc ); Seek to position loc in the directory assosiated with dirp.

void rewinddir ( DIR *dirp ); Seek to the beginning of directory assosiated with dirp.

int closedir ( DIR *dirp ); Close directory assosiated with dirp.

int ftw ( char *path, int (*fn )(), int param ); Recursively walk tree rooted at path applying function fn.

U*IX Compatibility Routines U*IX Compatibility Routines

U*IX Compatibility Routines

#include ⟨unixlib.h⟩

void exit ( int ret ); Exit the current process without cleaning up. (This is a Pterm())

int access ( const char *fname, int mode ); Check, if file fname is accessable with mode mode.

int chdir ( const char *dname ); Chane the current working directory to dname including drive specification.

int chmod ( const char *fname, int mode ); Change permissions of file fname to mode.

int chown ( const char *fname, int uid, int gid ); Change owner and group of file fname. (Fake for now)

int close ( int fd ); Close the file assosiated with file descriptor fd.

int creat ( const char *fname, unsigned mode );

Create the file fname with mode mode. int dup ( int fd );

Duplicate filedescriptor fd. int dup2 ( int fd1, int fd2 );

Duplicate filedescriptor fd1 to fd2. int execve ( char *path, char **argv, char **envp ); int execv ( char *path, char **argv );

Execute a new process from path after a fork().

int fork ( ); int vfork ( );

Simulate a non multitasking fork. vfork shares data + stack with parent.

char *getcwd ( char *buf, int size ); char *getwd ( char *buf );

Get the current working directory. int getgid ( ); int getuid ( );

Get user and group id’s. (Fake for now, returning alsways root).

int getegid ( ); int geteuid ( );

Get effective user and group id’s. char *getlogin ( );

Return the user’s login name. (Password file and environment are seached in order).

int getopt ( int argc, const char **argv, const char *opt ); Extract the command line options described by opt from argv.

int getpgrp ( ); int setpgrp ( );

Get or create a process group (This basically a fake; both return getpid()).

int getpid ( ); Return a process id for the currently running process (from the basepage).

int isatty ( int fd ); Check, if fd is associated with a terminal (screen).

int kill ( int, int );

int link ( const char *old , const char *new ); Make a new link from new to old. Always fails. int symlink ( char *old , char *new );

Make a new symbolic link from new to old. Env. UNIX-MODE determines behavior.

int readlink ( char *fname , char *buf, int siz );

Read the link for fname into buf. long lseek ( int fd, long pos, int whence );

Set the current file posistion to position pos relative to whence.

int mkdir ( const char *dname ); Make a directory with name dname.

char *mktemp ( char *pattern ); Return a filename for a temporary file, build after pattern.

int open ( const char *fname, int mode, …); Open the file fname with mode mode.

void psignal ( int signal, const char *prefix ); Print a error message describing the signal with a user comment.

int rmdir ( const char *dname ); Remove the directory with name dname.

int read ( int fd, void *buf, int cnt ); long lread ( int fd, void *buf, long cnt );

Read cnt bytes from file descriptor fd into buffer buf. void *sbrk ( size t size ); void *lsbrk ( long size );

Emulation of the U*ix sbrk() system call. void setlinebuf ( FILE *fp );

Change the buffering on stream fp from block/unbuffered to line buffered.

int setgid ( int gid ); int setuid ( int uid );

Set the effective user and group id. void ( *signal(int signum, void (*func)(int)))(int );

Make func the handler for signal signum. Returns previous setting.

int sleep ( int n ); Sleep for n number of seconds.

int stime ( long *time );

Set the current time to time in U*ix format. long tell ( int fd );

Get the current file position of the file associated with fd.

int times ( struct tms *buf ); Get process times into buf.

int umask ( int mode ); Set access mask. (Fake for now)

int unlink ( const char *fname );

Remove the file with name fname. int usleep ( long n );

Sleep for n number of milliseconds. int utime ( const char *fname, const struct utimbuf *ftime );

Set the modification time and date of file fname to ftime. int write ( int fd, const void *buf, int cnt ); long lwrite ( int fd, const void *buf, long cnt );

Write cnt bytes from buffer buf to file descriptor fd. int wait ( int *exit code );

Wait for child process.

Password and Group Handling Miscellaneous

Password and Group Handling

#include ⟨unixlib.h⟩ int endpwent ( );

Close password file. int setpwent ( );

Open password file for further operations. void setpwfile ( char *fname );

Use the fname instead of /etc/passwd as password file.

The following routines already use the above functions. #include ⟨pwd.h⟩ struct passwd *getpwent ( );

Return an entry from the password file. struct passwd *getpwuid ( int uid );

Return the entry from the password file for uid. struct passwd *getpwnam ( char *user );

Return the entry from the password file for user.

#include ⟨grp.h⟩ struct group *getgrgid ( int gid );

Return the entry from the group file for gid. (Mostly fake, returning root or user as groupnames)

struct group *getgrnam ( char *gname ); Return the entry from the group file for gname. (Mostly fake, returning root or user as groupnames)

Value Conversion

#include ⟨stdlib.h⟩ double atof ( const char *str );

Return double value of number presented in str. int atoi ( const char *str );

Return int value of number presented in str. long atol ( const char *str );

Return long value of number presented in str. int abs ( int val ); long labs ( long val );

Return absolute value of val. long strtol ( const char *nptr, char **endptr, int base );

unsigned long strtoul ( const char *nptr, char **endptr,

int base );

Return the value of the number in nptr with base putting the endaddress of the numerical string into endptr.

double strtod ( const char *nptr, const char **endptr ); Return the double value of the number in nptr putting the endaddress of the numerical string into endptr.

#include ⟨support.h⟩ char * itoa ( int val, char *buf, int radix ); char * ltoa ( long val, char *buf, int radix ); char * ultoa ( unsigned long val, char *buf, int radix );

Convert the value val to a string in buf according to radix.

#include ⟨locale.h⟩ struct lconv *localeconv ( );

Get rules of the current locale char *setlocale ( int category , const char *name );

Define locale named in name.

Miscellaneous

#include ⟨stdlib.h⟩ void abort ( );

Immediatly abort the running program. int atexit ( void (*func)() );

Register a function for execution on termination. void exit ( int ret );

Exit current process with return value ret. div t div ( int num, int denom ); ldiv t ldiv ( long num, long denom );

Perform division and return both quotient and remainder.

int rand ( ); Return a pseudo random number in the range from 0 to

RAND MAX.

void srand ( unsigned int seed ); Use seed to initialize the pseudo-random number generator.

long random ( ); Return a pseudo random number in the range from 0 to 2ˆ 31 - 1.

int srandom ( unsigned int x ); Seed generator for random.

char *initstate ( unsigned seed, char *arg state, int n ); Initialize state array of generator for random.

char *setstate ( char *arg state ); Switch state of generator for random.

char *getenv ( const char *name );

Get the contents of the environment variable name.

void *bsearch ( const void *key, const void *base,

size t num, size t size, int (*cmp)() );

Binary search a field starting at base with num elements each size size for key.

void qsort ( void *base, size t num,

size t size, int (*cmp)() ); Quick sort an array of num elements with size size starting at base.

#include ⟨support.h⟩ int console input status ( int handle );

Check, if character is available from standard CON:. (This is the same as Cconis)

unsigned int console read byte ( int handle ); Raw input from standard CON: without echoing to screen. (This is the same as Crawcin)

void console write byte ( int handle, int character ); Write character c to handle handle. (This is a Fwrite with count 1)

void dos2unx ( const char *t fname, char *u fname );

Convert filenames from TOS format to U*ix format. time t dostime ( time t );

Convert U*ix time to TOS time and date (lower word = time, upper word = date).

char *findfile ( char *fname, char *path, char **ext ); Locate the file fname along the paths in path with ext containing possible extensions.

time t unixtime ( unsigned tostime, unsigned tosdate ); Convert a TOS time/date pair into a U*ix time.

void unx2dos ( const char *u fname, char *t fname ); Convert filenames from U*ix format to TOS format.

Miscellaneous GEMDOS Calls via Trap 1

void fnmapfunc ( fnmapfunc t u2dos, fnmapfunc t dos2u ); Set mapping functions for the unx2dos and dos2unx routines.

long get sysvar ( void *var ); Get the contents of the system variable var.

void set sysvar to long ( void *var, long val ); Set the system variable var to the long value val.

Profiling

also see gprof.ttp and -pg option to gcc void monstartup ( void *lpc, void *hpc );

High level interface to profil. [lpc,hpc] is the range to sample. Necessary memory is dynamically allocated.

void monitor ( void *lpc, void *hpc, void *buf,

size t bsiz, unsigned int nfunc );

Low level interface to profil. buf is a user supplied buffer. PC samples over [lpc,hpc] and mcount() call records are accumulated in buf.

void moncontrol ( long flag ); Selectively control profiling in a program.

int profil ( void *buf, size t bsiz, size t off, int shift ); Execution time profil. Pc is examined every 20ms, (PCoff)≫ shift if in range, will increment short in buf.

GEMDOS Calls via Trap 1

#include ⟨osbind.h⟩ The following assignment is valid by default:

Device  handle
CON:  0  Keyboard
CON:  1  Screen
AUX:  2  Serial port
PRN:  3  Parallel port

long Cauxin ( );

Read character from standard AUX:. short Cauxis ( );

Check, if character is available from standard AUX:. short Cauxos ( );

Check, if character can be written to standard AUX:. void Cauxout ( short c );

Write character c to standard AUX:. long Cconin ( );

Read a character from standard CON:. short Cconis ( );

Check, if character is available from standard CON:. short Cconos ( );

Check, if character can be written to standard CON:. void Cconout ( short c );

Write character c to standard CON:. void Cconrs ( char *buf );

Read edited data from standard CON:. buf[0] contains number of characters minus 1 to read.

void Cconws ( const char *str ); Write string str to standard CON:.

long Cnecin ( ); Raw input from standard CON: without echoing to screen, but with interpretation of CTRL-S, CRTL-Q and CRTL-C. short Cprnos ( );

Check, if character can be written to standard PRN:. void Cprnout ( short c );

Write character c to standard PRN:. long Crawcin ( );

Raw input from standard CON: without echoing to screen.

long Crawio ( short data ); Raw I/O to standard CON:. If data = 0xff read from CON:, otherwise output to CON:.

short Dcreate ( const char *dname ); Create a directory with name dname.

long Ddelete ( const char *dname ); Remove a directory with name dname.

long Dfree ( DISKINFO *buf, short drv ); Get available space of drive drv into buf. drv = 0 means current drive.

short Dgetdrv ( );

Get the number of the default drive. long Dgetpath ( void *buf, short drv );

Get the current directory of drive drv. drv = 0 means current drive.

long Dsetdrv ( short d );

Set the number of the default drive. long Dsetpath ( const char *path );

Set path for current drive to path. short Fattrib ( const char *fname, short rwflag, short attr );

Get (rwflag = 0) or set (rwflag = 1) attribute byte of file fname.

long Fclose ( short handle );

Close the file assosiated with handle. struct dta *Fgetdta ( );

Get the current disk transfer address. long Fcreate ( const char *fname, short mode );

Create file fname with mode mode. long Fdatime ( DOSTIME *timeptr, short hdl, short rwflg );

Get (rwflag = 0) or set (rwflg = 1) the time structure of the file associated by handle hdl.

long Fdelete ( const char *fname );

Delete file with name fname. long Fdup ( short handle );

Return a second handle for a standard handle (0…5). long Fforce ( short Hstd, short Hnew );

Replace one of the standard handles (0…5) with Hnew. long Fopen ( const char *fname, short mode );

Open file fname with mode mode. long Fread ( short handle, long cnt, void *buf );

Read cnt bytes into buf from file assosiated with handle. short Frename ( const char *old, const char *new );

Change name of file from old to new. Also directories long Fseek ( long pos, short handle, short whence );

Set access pointer to position pos relative to whence. void Fsetdta ( struct dta *ptr );

Set the current disk tranfer address to ptr. long Fsfirst ( const char *filespec, short attr );

Get first directory slot, which matches filespec and attr. long Fsnext ( );

Get next match of search started by Fsfirst. long Fwrite ( short handle, long cnt, const void *buf );

Write cnt bytes from buf to file assosiated with handle.

GEMDOS Calls via Trap 1 BIOS Calls via Trap 13

long Malloc ( long size ); Allocate size bytes of memory.

long Mfree ( void *ptr ); Release block of memory.

long Mshrink ( long ptr, long size ); Shrink size of memory block obtained by Malloc.

long Pexec ( short mode, const char *prog, const char *tail,

char **env );

Execute prog with mode mode. void Pterm ( short rv );

Terminate current process with return value rv. void Pterm0 ( );

Terminate current and return to calling process. void Ptermres ( long save, short ret );

Terminate and stay resident, but keep save bytes of memory.

long Super ( void *stack ); Inquire (stack = 1), set (stack = 0) or return from (stack > 0) supervisor mode.

short Sversion ( );

Get the version number of GEMDOS. short Tgetdate ( );

Get the GEMDOS internal date. The harware clock is read in MEGA ST’s. The return value is composed of the following fields:

Bits  Meaning (Range)
0…4  Day (0…31)
5…8  Month (1…12)
9…15  Year (0…119)(+1980)

short Tgettime ( ); Get the GEMDOS internal time. The return value is composed of the following fields:

Bits  Meaning (Range)
0…4  Seconds (0…29) have to be doubled
5…10  Minutes (0…59)
11…15  Hours (0…23)

long Tsetdate ( short date );

Set the GEMDOS internal date. long Tsettime ( short time );

Set the GEMDOS internal time.

BIOS Calls via Trap 13

#include ⟨osbind.h⟩ Available devices for BIOS calls are:

Device  #
PRT:  0  parallel port
AUX:  1  serial port
CON:  2  console
MIDI:  3  MIDI port
IKBD:  4  keyboard processor
RAWCON:  5  console (no terminal emulation)

long Bconin ( short dev ); Read a character from device dev. (Allowed devices: 0…3

void Bconout ( short dev, short c ); Write character c to device dev. (Allowed devices: 0…5) short Bconstat ( short dev );

Get the status of the input device dev. (Allowed devices: 1…3).

short Bcostat ( short dev ); Get the status of the output device dev. (Allowed devices: 0…4)

long Drvmap ( ); Get the bitmap of available drives.

BPB *Getbpb ( short dev ); Get the BIOS parameter block of device dev.

void Getmpb ( void *ptr ); The memory parameter block pointed to by ptr is filled.

long Kbshift ( short mode ); Get (mode = -1) or set the current keyboard status. The return value is composed of the following fields:

Bit  Meaning
0  Right shift key
1  Left shift key
2  Control key
3  Alternate key
4  Caps lock key
5  r. mouse buttton (ClrHome)
6  l. mouse button (Insert)
7  Reserved (0)

short Mediach ( short dev ); Check, if disk in device dev has changed.

short Rwabs ( short rwflag, long buf, short n,

short sector, short dev );

Read (rwflag = 0) or write (rwflag = 1) n logical sectors from device dev.

void (*)() Setexc ( short vecnum, long vecptr ); Get (vecptr = -1) or set an M68000 exception vector.

long Tickcal ( ); Get the number of milliseconds between two calls of tickcal.

XBIOS Calls via Trap 14

#include ⟨osbind.h⟩ void Bioskeys ( );

Reset to initial keyboard mapping tables. short Blitmode ( short flag );

Configure the blitter chip. short Cursconf ( short rate, short attr );

Configure the cursor and blinking speed. void Dosound ( void *ptr );

Output a number of bytes to the soundchip.

short Floprd ( void *buf, long filler, short drv,

short sect, short trk, short side, short n );

Read physically n sectors from floppy drive drv.

short Flopwr ( void *buf, long filler, short drv,

short sect, short trk, short side, short n );

Write physically n sectors to floppy drive drv.

short Flopfmt ( void *buf, long filler, short drv, short spt,

short trk, short side, short i, long m, short v );

Format track trk on drive drv with spt sectors per track.

short Flopver ( void *buf, long filler, short drv, short spt,

short trk, short side, short n );

Read a number of sectors and compare with memory.

XBIOS Calls via Trap 14 XBIOS Calls via Trap 14

short Getrez ( ); Get the current display resolution (0 = low, 1 = mid, 2 = high).

long Gettime ( ); Get the time from the hardware clock (lower word = time, upper word = date).

short Giaccess ( short data, short reg ); Get or set a register of the GI sound chip. Set bit 8 of reg for write operation.

void Ikbdws ( short cnt, void *ptr ); Write a sequence of cnt+1 bytes to the keyboard processor.

void Initmous ( short type, void *param, void *vptr );

Initialize the mouse cursor routines. IOREC *Iorec ( short ioDEV );

Get a pointer to a device specific buffer. void Jdisint ( short vnum );

Disable interrupt vnum of the MFP 68901 chip. void Jenabint ( short vnum );

Enable interrupt vnum of the MFP 68901 chip. KBDVECS *Kbdvbase ( );

Get a pointer to the KBDVECS structure. short Kbrate ( short delay, short reprate );

Get or set keyboard repeat rate. KEYTAB *Keytbl ( void *nrml, void *shft, void *caps );

Set the addresses of the keyboard mapping tables (-1 = don’t change).

void *Logbase ( ); Get the start address of the logical display memory.

void Mfpint ( short vnum, void *vptr ); Set the interrupt vectors of the MFP 68901 chip.

void Midiws ( short cnt, void *ptr ); Write a sequence of cnt+1 bytes to the MIDI-port.

void Offgibit ( short ormask ); Clear a bit in “PORT A” register of the GI chip.

void Ongibit ( short andmask ); Set a bit in “PORT A” register of the GI chip.

void *Physbase ( ); Get the start address of the physical display memory.

void Protobt ( void *buf, long serial,

short dsktyp, short exec );

Create a boot sector in memory. void Prtblk ( void *pblkptr );

Special hardcopy routine, not unlike the Scrdmp() routine.

long Random ( );

Get a 24 bit random number.

long Rsconf ( short baud, short flow, short uc,

short rs, short ts, short sc );

Set the communication parameters for the serial port. void Scrdmp ( );

Dump the current screen to the printer. short Setcolor ( short colornum, short color );

Get (color = -1) or set contents of color register.

void Setpallete ( void *palptr ); Set the color palette of the video hardware.

short Setprt ( short config ); Get or set the current printer configuration.

The bits of the return value are assigned as follows:

Bit  Off  On
0  Matrix-  Daisy Wheel printer
1  color  monochrom
2  Atari-  Epson printer
3  Draft-  High quality
4  Centronics-  RS232 interface
5  Endless  Single sheet paper

void Setscreen ( void *lscrn, void *pscrn, short rez ); Set the logical and physical display memory start address and the current screen resolution.

void Settime ( long time date ); Set the hardware clock to time date(lower word = time, upper word = date. void *Ssbrk ( short size );

Reserve size bytes at the end of the physical memory (Dummy routine in all TOS versions).

long Supexec ( void *funcptr ); Execute a subroutine in supervisor mode.

void Vsync ( ); Wait until the verical blank interrupt has bitten.

void Xbtimer ( short timer, short ctrl,

long data, void *vptr );

Set and start the MFP 68901 timer.

lineA Calls

#include ⟨linea.h⟩ void linea0 ( );

Initialize lineA. void linea1 ( ); Put pixel.

int linea2 ( ); Get pixel. void linea3 ( );

Draw line. void linea4 ( );

Horizontal line. void linea5 ( );

Draw rectangle. void linea6 ( );

Filled polygon. void linea7 ( BBPB *ptr );

Bit blit. void linea8 ( ); Text blit. void linea9 ( );

Show mouse. void lineaa ( );

Hide mouse. void lineab ( );

Mouse form. void lineac ( void *ptr ); Undraw sprite.

void linead ( int x, int y, SFORM *sprite, void *ptr ); Draw sprite.

void lineae ( ); Copy raster. lineA Calls

System Variables and Magic Numbers

void lineaf ( );

Seed fill.

VT52 Escape Seqences

#include ⟨vt52.h⟩

Mnemonic  Sequence Meaning
C UP  \033A  cursor one line up
C DOWN  \033B  cursor one line down
C RIGHT  \033C  cursor one column right
C LEFT  \033D  cursor one column left
CLEAR HOME  \033E  clear screen, cursor home
HOME  \033H  cursor home
SCROLL UP  \033I  cursor one line up (scroll)
CLEAR DOWN  \033J  clear to end of screen
DEL EOL  \033K  clear until end of line
INS LINE  \033L  insert line
DEL LINE  \033M  delete line
CURS LOC  \033Y%c%c set cursor to position
CHAR COLOR  \033b%c set char. color
BG COLOR  \033c%c set background color
DEL BOP  \033d  erase to start of page
C ON  \033e  switch cursor on
C OFF  \033f  switch cursor off
C SAVE  \033j  store cursor position
C RESTORE  \033k  restore cursor position
ERASE L  \033l  clear cursor line
DEL BOL  \033o  clear until beg. of line
REV ON  \033p  inverse on
REV OFF  \033q  inverse off
WRAP ON  \033v  automatic line wrap on
WRAP OFF  \033w  automatic line wrap off

System Variables and Magic Numbers

#include ⟨sysvars.h⟩

Name  Address
proc lives  (unsigned long *) 0x380
etv timer  (void (**)()) 0x400
etv critic  (void (**)()) 0x404
etv term  (void (**)()) 0x408
memvalid  (unsigned long *) 0x420
mencntlr  (unsigned char *) 0x424
resvalid  (unsigned long *) 0x426
resvector  (void (**)()) 0x42a
phystop  (unsigned long *) 0x42e
membot  (unsigned long *) 0x432
memtop  (unsigned long *) 0x436
memval2  (unsigned long *) 0x43a
flock  (short *) 0x43e
seekrate  (short *) 0x440
timr ms  (short *) 0x442
fverify  (short *) 0x444
bootdev  (short *) 0x446
palmode  (short *) 0x448
defshiftmd  (unsigned char *) 0x44a
sshiftmd  (short *) 0x44c
v bas ad  (void *) 0x44e
vblsem  short *) 0x452
nvbls  (short *) 0x454
vblqueue  (void (***)()) 0x456

colorptr  (short **) 0x45a
vbclock  (unsigned long *) 0x462
frclock  (unsigned long *) 0x466
hz 200  (unsigned long *) 0x4ba
conterm  *((char *) 0x484
savptr  (long *) 0x4a2
sysbase  (long *) 0x4f2
shell p  (long *) 0x4f6
PROC LIVES MAGIC  0x12345678L
MEMVALID MAGIC  0x752019F3L
MEMVAL2 MAGIC  0x237698AAL
RESVALID MAGIC  0x31415926L

Error Numbers

#include ⟨errno.h⟩

ENOERR  0  no error
EERROR  1  generic error
EDRNRDY  2  drive not ready
EUKCMD  3  unknown command
ECRC  4  crc error
EBADREQ  5  bad request
ESEEK  6  seek error
EUKMEDIA  7  unknown media
ESECTOR  8  sector not found
EPAPER  9  no paper
EWRITE  10  write fault
EREAD  11  read fault
EGENERIC  12  general mishap
EROFS  13  write protect
ECHMEDIA  14  media change
EUKDEV  15  unknown device
EBADSEC  16  bad sectors
EIDISK  17  insert disk
EINVAL  32  invalid function number
ENOENT  33  file not found
EPATH  34  path not found
EMFILE  35  too many open files
EACCESS  36  access denied
EBADF  37  invalid handle
ENOMEM  39  insufficient memory
EFAULT  40  invalid memory block request
ENXIO  46  invalid drive
EXDEV  48  cross device rename
ENMFILES  49  no more files (Fnext)
ERANGE  62  range error
EDOM  63  domain error
EBADARG  64  range error/context unknown
EINTERNAL  65  internal error
ENOEXEC  66  invalid program load format
ESBLOCK  67  set block failed/growth restraints
EEXIST  80  file exists (open)
ENAMETOOLONG  81  file exists (open)
ENOTTY  82  not a tty (ioctl)
EAGAIN  EDRNRDY try again later
ENOTDIR  EPATH * preliminary *
Copyright \begin{matrix}c \\ ◯ \end{matrix} 1990 Free Software Foundation, Inc.

originally designed by Stephen Gildea modified for Atari ST GNU C Library by Frank Ridderbusch

Permission is granted to make and distribute copies of this card provided the copyright notice and this permission notice are preserved on all copies.