koreth%panarthea.ebay@sun.com (Steven Grimm) (08/21/89)
Submitted-by: uunet.UU.NET!unido!sbsvax!roeder (Edgar Roeder) Posting-number: Volume 2, Issue 79 Archive-name: gcclib2-patch1 Once again Murphy has caught me. In the GCC library posted was a little bug. When seeking on an output file (like stdout) the old code tried to read in a new buffer from that 'file'. On stdout this means that on every fflush-call the program reads one line of text. There was also a typo in the CR/LF conversion of fgetc. The files in the appended shar archive should replace the corresponding files of the library. - Edgar -------------------------------------------------------------------------------- #!/bin/sh # shar: Shell Archiver (v1.22) # # Run the following text with /bin/sh to create: # console.c # fgetc.c # fseek.c # read.c # include/osbind.h # sed 's/^X//' << 'SHAR_EOF' > console.c && X/* console IO stuff. Abstracted out here cause I'm having so much trouble X getting Bconout and Cconout to work. X X Well, after a lot of fooling around, it looks like I can almost get the X effect I want (single byte read with no echo) by doing Freads with X length 1. That does everything right except that it echos printable X ascii chars; ie anything #x20 .. #x7F. We kludge around that by X arranging for the caller (read) to know which chars have been echoed. X Sigh. X X There seem to be some people in the atari st community who have never X heard about the st's character set. There are some chars > 0x7F which X can be printed. And they will be printed. X This code assumes that nowbody tries to read from stderr if stdin is X redirected to AUX:. (er) X If we use Crawcin()/Cconis() we avoid problems with typeahead. X*/ X X#include <osbind.h> X#include <file.h> X Xint console_read_byte(gem_handle) Xint gem_handle; X{ X /* char c[1]; */ X X return(Crawcin()); /* isatty(gem_handle) == TRUE */ X/* Fread(gem_handle, 1L, &c[0]); X return(c[0] & 0xFF); */ X} X Xconsole_write_byte(gem_handle, c) Xint gem_handle; Xchar c; X{ X char ch[1]; X X/* if (gem_handle < 0) X Cconout(c); X else */ X { X ch[0] = c; X Fwrite(gem_handle, 1L, &ch[0]); X } X} X X/* return status (nbytes pending) X This is completely brain-dead. always return 0 for now */ Xint console_status(gem_handle) Xint gem_handle; X{ X return(Cconis()); X/* return(0); */ X/* X if (gem_handle < 2) X return(Bconstat(2)); X else X if (handle == 2) X return(Bconstat(1)); X else X return(Bconstat(handle)); /* it'd sure be nice to know if this X is right. Too bad Atari doesn't X want anyone to see their X documentation... */ X} SHAR_EOF chmod 0644 console.c || echo "restore of console.c fails" sed 's/^X//' << 'SHAR_EOF' > fgetc.c && X X/* fgetc */ X X#include <file.h> X#include "std-guts.h" X Xstatic int fgetc_internal(f) Xstruct file * f; X{ X X if (!f) return(EOF); X if (f->eof_p) return(EOF); X if (!f->open_p) return(EOF); X if ((f->flags & 0x03) == O_WRONLY) return(EOF); X if (f->buf_max > f->buf_index) X { X int result = f->buf[f->buf_index] & 0xFF; X X f->buf_index++; X/* X#ifdef DEBUG X fprintf(stderr, " >%02X", result); X#endif X*/ X return(result); X } X X/* ok, get a new buf */ X f->file_position += f->buf_max; /* base pos for next buf */ X f->buf_max = read(f->handle, &f->buf, BUFSIZE); X f->buf_index = 0; X if (f->buf_max <= f->buf_index) /* didn't get anything? */ X { X f->eof_p = 1; /* remember the eof */ X if (f->buf_max < 0) X f->last_file_error = f->buf_max; X else X f->last_file_error = 0; X#ifdef DEBUG X fprintf(stderr, "fgetc(%X)->EOF\r\n", f); X#endif X return(EOF); X } X else X { X int result = f->buf[f->buf_index] & 0xFF; X X f->buf_index++; X#ifdef DEBUG X fprintf(stderr, "fgetc(%X)->%02X\r\n", f, result); X#endif X return(result); X } X} X Xint fgetc(f) Xstruct file * f; X{ X int ch; X int next_ch; X X ch = fgetc_internal(f); X if ((ch == '\r') && !(f->flags & FILE_BINARY_P) && !isatty(fileno(f))) X /* ttys are doing this with CRMOD in read */ X { X /* next char '\n'? if so, just return the linefeed, else put it X back and return the cr */ X next_ch = fgetc_internal(f); X if (next_ch == '\n') X ch = next_ch; X else X ungetc(next_ch, f); /* doesn't deal with EOF right... BFD */ X } X return(ch); X} SHAR_EOF chmod 0644 fgetc.c || echo "restore of fgetc.c fails" sed 's/^X//' << 'SHAR_EOF' > fseek.c && X#include <file.h> X#include "std-guts.h" X#include <errno.h> X Xlong fseek(f, pos, mode) Xstruct file * f; Xlong pos; Xint mode; X{ X long new_pos; X X f->eof_p = 0; /* just in case */ X switch (mode) X { X case L_SET: { new_pos = pos; break; }; X case L_INCR: { new_pos = f->file_position + f->buf_index + pos; X mode = L_SET; X break; }; X case L_XTND: { new_pos = pos; break; }; X default: { errno = EBADARG ; return(-1); }; X }; X#ifdef DEBUG X fprintf(stderr, "fseek: %d,%d. filepos %d, idx %d max %d\n", X pos, mode, f->file_position, f->buf_index, f->buf_max); X#endif X if ((mode != L_XTND) && /* always really seek in extend mode */ X (f->file_position <= new_pos) && X ((f->file_position + f->buf_max) > new_pos)) /* have it already? */ X { X f->buf_index = new_pos - f->file_position; /* yes, point at it */ X#ifdef DEBUG X fprintf(stderr, " same buf: new idx %d\n", f->buf_index); X#endif X return(0); X } X if (file_output_p(f)) /* output; flush buf */ X fflush(f); X f->buf_index = f->buf_max = 0; /* flush buf */ X X if (file_input_p(f)) { X/* the requested index is not in the current buffer. if it's less than the X current file-position, assume we're walking backwards thru the file, and X set the real position to a half bufferful before the requested pos, and set X indices accordingly */ X X if (new_pos < f->file_position) X { X if (new_pos < (BUFSIZE / 2)) /* too close to a bufferful? */ X { X f->buf_index = new_pos; /* say the idx is this far in */ X new_pos = 0; /* and start at beginning */ X } X else X { X new_pos -= ((BUFSIZE / 2) - 1); /* set up to seek to pos - bufsize + 1 */ X f->buf_index = (BUFSIZE / 2) - 1; /* and point at last byte */ X } X } X new_pos = lseek(f->handle, new_pos, mode); X if (new_pos >= 0) X { X f->file_position = new_pos; X f->buf_max = read(f->handle, &f->buf, BUFSIZE); X } X } else { X new_pos = lseek(f->handle, new_pos, mode); X if (new_pos >= 0) f->file_position = new_pos; X } X#ifdef DEBUG X fprintf(stderr, " seeked to %d\n", f->file_position); X#endif X if (new_pos < 0) X return (new_pos); X else X return (0); X} SHAR_EOF chmod 0644 fseek.c || echo "restore of fseek.c fails" sed 's/^X//' << 'SHAR_EOF' > read.c && X/* X * Cross Development System for Atari ST X * Copyright (c) 1988, Memorial University of Newfoundland X * X * $Header: read.c,v 1.2 88/02/03 22:56:30 m68k Exp $ X * X * $Log: read.c,v $ X * X * 1.5 er X * X * Added /dev/null dummy handle. X * Fix it : When adding 'continue' after raise(SIGINT) and raise(SIGQUIT), get X * unexpected results in Emacs (perhaps problems with EOF in fgetc()). X * Moved __col_pos to write.c (it's always included because of fflush in exit) X * X * 1.4 er X * X * Revision 1.4 89/01/15 X * Added support for function keys (they give an Esc-sequence with the X * scan-code as parameter), META-key (Alternate sets the highest bit) and X * O_NDELAY mode (no waiting if there is no available input). META-translation X * is controled via the META-bit in __ttymode (set by ioctl()). X * X * 1.3 jrd X * X * Revision 1.2 88/02/03 22:56:30 m68k X * Added unix like tty driver stuff X * X * Revision 1.1 88/01/29 17:31:39 m68k X * Initial revision X * X */ X#include <osbind.h> X#include <ioctl.h> X#include <file.h> X#include <errno.h> X#include <signal.h> X#include "tchars.h" X X#define META_MASK 0x80 X#define DEL 0x7f X X#define iswhite(c) ((c) == ' ' || (c) == '\t') X#define isvisable(c) ((c) >= ' ' && (c) < DEL) X#define echochar(c) if (__ttymode & ECHO) (void) _echochar(c, fd); else X#define delchar(n) if (__ttymode & ECHO) _delchar(n, fd); else X X# ifndef NULL X# define NULL 0 X# endif /* NULL */ X Xstatic int str_length(unsigned char * p, int n); X Xextern int __col_pos; Xstatic int start_col; Xstatic unsigned char *thebuf; X Xstatic int _echochar(); Xstatic int str_length(); Xstatic void _delchar(); X Xunion key { X int i; X struct { X char shift_state; X char scan_code; X char filler; X unsigned char ascii_code; X } k; X}; X X/* possible shift_state's */ X#define SHIFT_RIGHT 1 X#define SHIFT_LEFT 2 X#define SHIFT (SHIFT_LEFT|SHIFT_RIGHT) X#define CONTROL 4 X#define ALTERNATE 8 X#define CAPS_LOCK 16 X#define MOUSE_RIGHT 32 X#define MOUSE_LEFT 64 X#define MOUSE (MOUSE_LEFT|MOUSE_RIGHT) X Xstatic enum { Esc, Number, Key } _fn_state; Xstatic char _fn_key; X Xint Xread(int fd, unsigned char *buf, int nbytes) X{ X#ifdef DEBUG X char dbgbuf[64]; X#endif X X int rval; X int cnt = 0; X unsigned char *p = buf; X union key ch; X X if (fd == 1234 || nbytes <= 0) return(0); /* /dev/null */ X if ((fd >= 0) && (!isatty(fd))) X { X if ((rval = Fread(fd, nbytes, (char *) buf)) < 0) X { X errno = -rval; X rval = -1; X } X#ifdef DEBUG X sprintf(dbgbuf, "read(%d, %X, %d)->%d\r\n", fd, buf, nbytes, rval); X dbgstr(dbgbuf); X#endif X return rval; X } X if ((__handle_stat[fd] & O_NDELAY) && _fn_state == Esc && !console_status(fd)) { X errno = EAGAIN; X return -1; X } X thebuf = buf; X start_col = __col_pos; X while (1) { X switch (_fn_state) { X case Number : X *p = '#'; X _fn_state = Key; X break; X case Key : X *p = _fn_key; X _fn_state = Esc; X break; X case Esc : X ch.i = console_read_byte(fd); X if((__ttymode & META) && !ch.k.shift_state) { X struct sgttyb sg; X X ioctl(fd, TIOCGETP, &sg); X ioctl(fd, TIOCSETN, &sg); X ch.k.shift_state = Kbshift(-1); X } X if((__ttymode & META) && X (ch.k.ascii_code & META_MASK)) { X /* these values are on the german keyboard */ X switch(ch.k.ascii_code) { X case 0x81 : X ch.k.ascii_code = '@'; break; X case 0x84 : X ch.k.ascii_code = ']'; break; X case 0x8E : X ch.k.ascii_code = '}'; break; X case 0x94 : X ch.k.ascii_code = '['; break; X case 0x99 : X ch.k.ascii_code = '{'; break; X case 0x9A : X ch.k.ascii_code = '\\'; break; X } X } X if (ch.k.scan_code == 0x72 && ch.k.ascii_code == '\r') X ch.k.ascii_code = '\n'; X else X /* 3B = F1, 72 = Enter, 53 = Delete, 60 = '<' */ X if ((ch.k.scan_code >= 0x3B && ch.k.scan_code <= 0x72 X && ch.k.scan_code != 0x53 && ch.k.scan_code != 0x60)) X { X if (ch.k.ascii_code) _fn_key = ch.k.ascii_code; X else _fn_key = ch.k.scan_code; X ch.k.ascii_code = 0x1B; /* ESC */ X _fn_state = Number; X } X *p = ch.k.ascii_code; X /* Alternate as META-key sets the highest bit */ X if ((__ttymode & META) && X (ch.k.shift_state & ALTERNATE)) { X if (_fn_state != Esc) _fn_key |= META_MASK; X else { X if (ch.k.shift_state & SHIFT) X ch.k.ascii_code = __keytab->shift[ch.k.scan_code]; X else if (ch.k.shift_state & CAPS_LOCK) X ch.k.ascii_code = __keytab->capslock[ch.k.scan_code]; X else X ch.k.ascii_code = __keytab->unshift[ch.k.scan_code]; X if (!ch.k.ascii_code) X ch.k.ascii_code = ch.k.scan_code; /* Alt 0 - Alt 9 */ X if (ch.k.shift_state & CONTROL) X ch.k.ascii_code &= 0x3F; X *p = ch.k.ascii_code | META_MASK; X } X } X break; X } X if (__ttymode & RAW) X { X if (__ttymode & ECHO) X { X console_write_byte(fd, *p); X if (*p == '\r') X __col_pos = 0; X else X if (isvisable(*p)) X __col_pos++; X } X if (++cnt >= nbytes || !(short)console_status(fd)) X return cnt; X p++; X continue; X } X if ((__ttymode & CRMOD) && *p == '\r') X *p = '\n'; X if (*p == __tchars[TC_INTRC]) X { X /* Do the bsd thing here, i.e. flush buffers X * and continue to read after the interupt X */ X echochar(*p); X p = buf; X cnt = 0; X raise(SIGINT); X } X else X if (*p == __tchars[TC_QUITC]) X { X echochar(*p); X p = buf; X cnt = 0; X raise(SIGQUIT); X } X else X if (*p == __tchars[TC_SUSPC]) X { X echochar(*p); X p = buf; X cnt = 0; X raise(SIGTSTP); X continue; X } X if (__ttymode & CBREAK) X { X if (*p == __tchars[TC_LNEXTC]) X *p = console_read_byte(fd); X if (__ttymode & ECHO) X { X if (*p == '\n' && (__ttymode & CRMOD)) X { X console_write_byte(fd, '\n'); X console_write_byte(fd, '\r'); X __col_pos = 0; X } X else X (void) _echochar(*p); X } X if (++cnt >= nbytes || !(short)console_status(fd)) X return cnt; X p++; X } X else X if (*p == __tchars[TC_LNEXTC]) X { X if (__ttymode & ECHO) X { X console_write_byte(fd, '^'); X console_write_byte(fd, '\b'); X } X *p = console_read_byte(fd); X echochar(*p++); X cnt++; X } X else X if (*p == __tchars[TC_EOFC]) X { X if (__ttymode & ECHO) X { X int i = _echochar(*p); X __col_pos -= i; X while (i-- > 0) X console_write_byte(fd, '\b'); X } X return cnt; X } X else X if (*p == '\n' || *p == __tchars[TC_BRKC]) X { X if (__ttymode & ECHO) X if (*p == '\n') X { X console_write_byte(fd, '\n'); X if (__ttymode & CRMOD) X { X console_write_byte(fd, '\r'); X __col_pos = 0; X } X } X else X (void) _echochar(*p); X return ++cnt; X } X else X if (*p == __tchars[TC_ERASE]) X { X if (cnt) X { X p--; X delchar(--cnt); X } X } X else X if (*p == __tchars[TC_KILL]) X { X while (--cnt >= 0) X { X delchar(cnt); X p--; X } X cnt = 0; X } X else X if (*p == __tchars[TC_WERASC]) X { X p--; X while (cnt && iswhite(*p)) X { X delchar(--cnt); X p--; X } X while (cnt && !iswhite(*p)) X { X delchar(--cnt); X p--; X } X p++; X } X else X if (*p == __tchars[TC_RPRNTC]) X { X unsigned char *s; X X echochar(__tchars[TC_RPRNTC]); X console_write_byte(fd, '\r'); X console_write_byte(fd, '\n'); X __col_pos = 0; X start_col = 0; X if (__ttymode & ECHO) X for (s = buf ; s < p ; s++) X echochar(*s); X } X else X { X echochar(*p++); X cnt++; X } X if (cnt >= nbytes) X return cnt; X } X /*NOTREACHED*/ X} X Xstatic int X_echochar(c, fd) Xunsigned char c; Xint fd; X{ X int len = 0; X X if (c & META_MASK) X { X console_write_byte(fd, 'M'); X console_write_byte(fd, '-'); X c &= ~META_MASK; X len += 2; X } X if (c < ' ') X { X if (c == '\t') X { X int i; X X len = ((__col_pos | 7) + 1) - __col_pos; X if (__ttymode & XTABS) X for (i = len ; i-- ;) X console_write_byte(fd, ' '); X else X console_write_byte(fd, '\t'); X } X else X { X console_write_byte(fd, '^'); X console_write_byte(fd, c + 0x40); X len += 2; X } X } X else X if (c == DEL) X { X console_write_byte(fd, '^'); X console_write_byte(fd, '?'); X len += 2; X } X else X { X console_write_byte(fd, c); X len++; X } X __col_pos += len; X return len; X} X Xstatic void X_delchar(n, fd) Xint n; Xint fd; X{ X int len; X unsigned char c = thebuf[n]; X X if (c & META_MASK) { X len = 2; X c &= ~META_MASK; X } else X len = 0; X if (c < ' ' || c == DEL) X { X if (c == '\t') X len = __col_pos - str_length(thebuf, n); X else X len += 2; X } X else X len++; X X __col_pos -= len; X while (len--) X { X console_write_byte(fd, '\b'); X console_write_byte(fd, ' '); X console_write_byte(fd, '\b'); X } X} X Xstatic int str_length(p, n) Xunsigned char *p; Xint n; X{ X int pos = start_col; X unsigned char c; X X while (n--) { X c = *p++; X if (c & META_MASK) X { X pos += 2; X c &= ~META_MASK; X } X if (c < ' ' || c == DEL) X { X if (c == '\t') X pos = (pos | 7) + 1; X else X pos += 2; X } X else X pos++; X } X return pos; X} SHAR_EOF chmod 0644 read.c || echo "restore of read.c fails" sed 's/^X//' << 'SHAR_EOF' > include/osbind.h && X#ifndef _OSBIND_H X#define _OSBIND_H X/* X * OSBIND.H Mnemonic names for operating system calls X * X * Adapted from Dale Schumacher's version to Mark Johnson C by Eric Gisin. X */ X X/* (er) 11.8.89 changed macros to inline functions */ X/* this is ABSOLUTELY necessary for Super(), */ X/* because the changed stack would be changed */ X/* back by the unlk instruction */ X X#pragma once X X/* ..sb correction of the calls 19/11/88 */ X/* hacked by jrd for GNU */ X X/* X * GEMDOS (trap1) X */ X Xstatic __inline volatile void XPterm0(void) X{ X __asm("movew #0x00,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X /* we will never come back, so we don't have to correct the stack */ X} X Xstatic __inline long XCconin(void) X{ X long ret; X X __asm("movew #0x00,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XCconout(short c) X{ X __asm("movew %0,sp@-" :: "g" (c)); X __asm("movew #0x02,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X} X Xstatic __inline long XCauxin(void) X{ X long ret; X X __asm("movew #0x03,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XCauxout(short c) X{ X __asm("movew %0,sp@-" :: "g" (c)); X __asm("movew #0x04,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X} X Xstatic __inline void XCprnout(short c) X{ X __asm("movew %0,sp@-" :: "g" (c)); X __asm("movew #0x05,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X} X Xstatic __inline long XCrawio(short data) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (data)); X __asm("movew #0x06,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XCrawcin(void) X{ X long ret; X X __asm("movew #0x07,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XCnecin(void) X{ X long ret; X X __asm("movew #0x08,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XCconws(char *s) X{ X __asm("movel %0,sp@-" :: "g" (s)); X __asm("movew #0x09,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline void XCconrs(char *buf) X{ X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movew #0x0A,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline short XCconis(void) X{ X short ret; X X __asm("movew #0x0B,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline const void XDsetdrv(short d) X{ X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movew #0x0E,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X} X Xstatic __inline short XCconos(void) X{ X short ret; X X __asm("movew #0x10,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XCprnos(void) X{ X short ret; X X __asm("movew #0x11,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XCauxis(void) X{ X short ret; X X __asm("movew #0x12,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XCauxos(void) X{ X short ret; X X __asm("movew #0x13,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XDgetdrv(void) X{ X long ret; X X __asm("movew #0x19,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XFsetdta(void *dta) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (dta)); X __asm("movew #0x1A,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X X/* X * The next binding is not quite right if used in another than the usual ways: X * 1. Super(1L) from either user or supervisor mode X * 2. ret = Super(0L) from user mode and after this Super(ret) from X * supervisor mode X * We get the following situations (usp, ssp relative to the start of Super): X * Parameter Userstack Superstack Calling Mode ret X * 1L usp ssp user 0L X * 1L usp ssp supervisor -1L X * 0L usp-6 usp user ssp X * 0L ssp ssp-6 supervisor ssp-6 X * ptr usp-6 ptr+6 user ssp X * ptr usp+6 ptr supervisor sr X * The usual C-bindings are safe only because the "unlk a6" is compensating X * the errors when you invoke this function. In this binding the "unlk a6" at X * the end of the calling function compensates the error made in sequence 2 X * above (the usp is 6 to low after the first call which is not corrected by X * the second call). X */ Xstatic __inline long XSuper(long ptr) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (ptr)); X __asm("movew #0x20,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XTgetdate(void) X{ X long ret; X X __asm("movew #0x2A,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XTsetdate(long date) X{ X __asm("movel %0,sp@-" :: "g" (date)); X __asm("movew #0x2B,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline long XTgettime(void) X{ X long ret; X X __asm("movew #0x2C,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XTsettime(long time) X{ X __asm("movel %0,sp@-" :: "g" (time)); X __asm("movew #0x2D,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline long XFgetdta(void) X{ X long ret; X X __asm("movew #0x2F,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline const short XSversion(void) X{ X short ret; X X __asm("movew #0x30,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline volatile void XPtermres(long save, short rv) X{ X __asm("movew %0,sp@-" :: "g" (rv)); X __asm("movel %0,sp@-" :: "g" (save)); X __asm("movew #0x31,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X /* if we don't call Ptermres(save,-32) and ignore SIGINT, */ X /* we can't come back */ X __asm("addql #8,sp"); X} X Xstatic __inline long XDfree(void *buf, short d) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movew #0x36,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XDcreate(char *path) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (path)); X __asm("movew #0x39,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XDdelete(char *path) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (path)); X __asm("movew #0x3A,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XDsetpath(char *path) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (path)); X __asm("movew #0x3B,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFcreate(char *fn,short mode) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (mode)); X __asm("movel %0,sp@-" :: "g" (fn)); X __asm("movew #0x3C,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFopen(char *fn,short mode) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (mode)); X __asm("movel %0,sp@-" :: "g" (fn)); X __asm("movew #0x3D,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XFclose(short handle) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movew #0x3E,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XFread(short handle,long cnt,char *buf) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movel %0,sp@-" :: "g" (cnt)); X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movew #0x3F,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #12,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XFwrite(short handle,long cnt,char *buf) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movel %0,sp@-" :: "g" (cnt)); X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movew #0x40,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #12,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFdelete(char *fn) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (fn)); X __asm("movew #0x41,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XFseek(long where,short handle,short how) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (how)); X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movel %0,sp@-" :: "g" (where)); X __asm("movew #0x42,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #10,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFattrib(char *fn,short rwflag,short attr) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (attr)); X __asm("movew %0,sp@-" :: "g" (rwflag)); X __asm("movel %0,sp@-" :: "g" (fn)); X __asm("movew #0x43,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #10,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFdup(short handle) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movew #0x45,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFforce(short Hstd,short Hnew) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (Hnew)); X __asm("movew %0,sp@-" :: "g" (Hstd)); X __asm("movew #0x46,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XDgetpath(char *buf,short d) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movew #0x47,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XMalloc(long size) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (size)); X __asm("movew #0x48,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XMfree(void *ptr) X{ X __asm("movel %0,sp@-" :: "g" (ptr)); X __asm("movew #0x49,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline short XMshrink(void *ptr,long size) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (size)); X __asm("movel %0,sp@-" :: "g" (ptr)); X __asm("clrw sp@-"); X __asm("movew #0x4A,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #12,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XPexec(short mode,char *prog,char *tail,char *env) X{ X long ret; X X __asm("movel %0,sp@-" :: "g" (env)); X __asm("movel %0,sp@-" :: "g" (tail)); X __asm("movel %0,sp@-" :: "g" (prog)); X __asm("movew %0,sp@-" :: "g" (mode)); X __asm("movew #0x4B,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #16,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline /* volatile */ void XPterm(short rv) X{ X __asm("movew %0,sp@-" :: "g" (rv)); X __asm("movew #0x4C,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X /* if we don't call Pterm(-32) and ignore SIGINT, we can't come back */ X __asm("addql #4,sp"); X} X Xstatic __inline short XFsfirst(char *filespec,short attr) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (attr)); X __asm("movel %0,sp@-" :: "g" (filespec)); X __asm("movew #0x4E,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFsnext(void) X{ X short ret; X X __asm("movew #0x4F,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline short XFrename(char *old,char *new) X{ X short ret; X X __asm("movel %0,sp@-" :: "g" (new)); X __asm("movel %0,sp@-" :: "g" (old)); X __asm("clrw sp@-"); X __asm("movew #0x56,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #12,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XFdatime(long *timeptr,short handle,short rwflag) X{ X __asm("movew %0,sp@-" :: "g" (rwflag)); X __asm("movew %0,sp@-" :: "g" (handle)); X __asm("movel %0,sp@-" :: "g" (timeptr)); X __asm("movew #0x57,sp@-"); X __asm("trap #1" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #10,sp"); X} X X X/* codes for Pexec */ X X#define PE_LOADGO 0 /* load & go */ X#define PE_LOAD 1 /* just load */ X#define PE_CBASEPAGE 2 /* just create basepage */ X#define PE_GO 3 /* just go */ X X/* zzz do the rest later */ X X/* X * BIOS (trap13) X */ X Xstatic __inline void XGetmpb(void *mpb) X{ X __asm("movew #0,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X} X Xstatic __inline short XBconstat(short DEV) X{ X short ret; X X __asm("movew %0,sp@-" :: "g" (DEV)); X __asm("movew #1,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movew d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XBconin(short DEV) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (DEV)); X __asm("movew #2,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void XBconout(short DEV,short c) X{ X __asm("movew %0,sp@-" :: "g" (c)); X __asm("movew %0,sp@-" :: "g" (DEV)); X __asm("movew #3,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #6,sp"); X} X Xstatic __inline long XRwabs(short rwflag,void *buf,short n,short sector,short d) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movew %0,sp@-" :: "g" (sector)); X __asm("movew %0,sp@-" :: "g" (n)); X __asm("movel %0,sp@-" :: "g" (buf)); X __asm("movew %0,sp@-" :: "g" (rwflag)); X __asm("movew #4,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addw #14,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void * XSetexc(short vnum,void *vptr) X{ X void *ret; X X __asm("movel %0,sp@-" :: "g" (vptr)); X __asm("movew %0,sp@-" :: "g" (vnum)); X __asm("movew #5,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #8,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XTickcal(void) X{ X long ret; X X __asm("movew #6,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline void * XGetbpb(short d) X{ X void *ret; X X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movew #7,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XBcostat(short DEV) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (DEV)); X __asm("movew #8,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XMediach(short d) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (d)); X __asm("movew #9,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XDrvmap(void) X{ X long ret; X X __asm("movew #10,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #2,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X Xstatic __inline long XKbshift(short mode) X{ X long ret; X X __asm("movew %0,sp@-" :: "g" (mode)); X __asm("movew #11,sp@-"); X __asm("trap #13" ::: "d0", "d1", "d2", "a0", "a1", "a2"); X __asm("addql #4,sp"); X __asm volatile ("movel d0,%0" : "=g" (ret)); X return(ret); X} X X#define Getshift() Kbshift(-1) X X/* X * XBIOS (trap14) X */ X#define Initmous(type,param,vptr) trap_14_wwll(0,type,param,vptr) X#define Physbase() trap_14_www(2) X#define Logbase() trap_14_www(3) X#define Getrez() (int)trap_14_www(4) X#define Setscreen(lscrn,pscrn,rez) trap_14_wllw(5,lscrn,pscrn,rez) X#define Setpallete(palptr) trap_14_wllw(6,palptr) X#define Setcolor(colornum,mixture) trap_14_wwll(7,colornum,mixture) X#define Floprd(buf,x,d,sect,trk,side,n) trap_14_wllwwwwwlw(8,buf,x,d,sect,trk,side,n) X#define Flopwr(buf,x,d,sect,trk,side,n) trap_14_wllwwwwwlw(9,buf,x,d,sect,trk,side,n) X#define Flopfmt(b,x,d,spt,trk,sd,i,m,v) trap_14_wllwwwwwlw(10,b,x,d,spt,trk,sd,i,m,v) X#define Midiws(cnt,ptr) trap_14_wwll(12,cnt,ptr) X#define Mfpint(vnum,vptr) trap_14_wwll(13,vnum,vptr) X#define Iorec(ioDEV) trap_14_wwll(14,ioDEV) X#define Rsconf(baud,flow,uc,rs,ts,sc) trap_14_wwwwwww(15,baud,flow,uc,rs,ts,sc) X#define Keytbl(nrml,shft,caps) trap_14_wlll(16,nrml,shft,caps) X#define Random() trap_14_www(17) X#define Protobt(buf,serial,dsktyp,exec) trap_14_wllwwwwwlw(18,buf,serial,dsktyp,exec) X#define Flopver(buf,x,d,sect,trk,sd,n) trap_14_wllwwwwwlw(19,buf,x,d,sect,trk,sd,n) X#define Scrdmp() trap_14_www(20) X#define Cursconf(func,rate) trap_14_www(21,func,rate) X#define Settime(time) trap_14_wllw(22,time) X#define Gettime() trap_14_www(23) X#define Bioskeys() trap_14_www(24) X#define Ikbdws(len_minus1,ptr) trap_14_wwll(25,len_minus1,ptr) X#define Jdisint(vnum) trap_14_www(26,vnum) X#define Jenabint(vnum) trap_14_www(27,vnum) X#define Giaccess(data,reg) trap_14_www(28,data,reg) X#define Offgibit(ormask) trap_14_www(29,ormask) X#define Ongibit(andmask) trap_14_www(30,andmask) X#define Xbtimer(timer,ctrl,data,vnum) trap_14_wwwwl(31,timer,ctrl,data,vnum) X#define Dosound(ptr) trap_14_wllw(32,ptr) X#define Setprt(config) trap_14_www(33,config) X#define Kbdvbase() trap_14_www(34) X#define Kbrate(delay,reprate) trap_14_www(35,delay,reprate) X#define Prtblk(pblkptr) trap_14_wllw(36,pblkptr) X#define Vsync() trap_14_www(37) X#define Supexec(funcptr) trap_14_wllw(38,funcptr) X#define Blitmode(flag) trap_14_www(64,flag) X#endif /* _OSBIND_H */ SHAR_EOF chmod 0644 include/osbind.h || echo "restore of include/osbind.h fails" exit 0