Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
as68 -u -L exit.s
as68 -u -L getchar.s
as68 -u -L ldiv.s
as68 -u -L lmul.s
as68 -u -L lrem.s
as68 -u -L putchar.s
c68 -c -L __length.c
c68 -c -L __prtint.c
c68 -c -L printf.c
c68 -c -L cputc.c

View File

@@ -0,0 +1,14 @@
# include "iodec.h"
/**
** put a single character
**/
int f_log 0;
cputc(c, fn)
char c;
int fn;
{
putchar(c);
}

View File

@@ -0,0 +1,9 @@
.globl _exit
.text
_exit: move.l macsbug,A0
jmp (A0)
*
.data
macsbug: .dc.w 0002
.dc.w 0008
.end

View File

@@ -0,0 +1,21 @@
*
* read one char from console
*
CRTS=$3ff01
CRTD=$3ff03
.globl _getchar
.globl _putchar
_getchar:
move.b CRTS,R0
and #1,R0 //receive register full
beq _getchar //not yet
move.b CRTD,R0 //read the char
and.l #$7f,R0 //leave only 7 bits
cmp.b #$0d,R0 //carriage return?
bne l0
move.b #$0a,R0 //turn into line feed
l0:
move R0,-(sp)
jsr _putchar //echo it
move (sp)+,R0 //pop arg
rts

View File

@@ -0,0 +1,24 @@
# define MAXFILES 15
struct fileps
{
char *buff; /* beginning of buffer */
char *bptr; /* current position */
int nchars; /* number of characters internal */
int bsize; /* size of buffer */
char eoferr; /* end of file flag */
char wrflag; /* mode flag */
char *pbuff; /* bottom of peek buffer */
};
struct fileps __filehdr[MAXFILES];
struct param
{
int bufsize; /* initial buffer size */
int peeksize; /* initial peek size */
};
extern struct param __param;
int __statbuf[MAXFILES];

View File

@@ -0,0 +1,84 @@
.globl _ldivr
.comm _ldivr,4
.globl _ldiv
.globl ldiv
.text
_ldiv:
ldiv:
~~ldiv:
~b=R4
~q=R5
~l1=R7
~l2=R6
~al1=8
~al2=12
~sign=R3
link R14,#-2
movem.l R2-R7,-(sp)
clr R3
clr.l R5
move.l 8(R14),R7
move.l 12(R14),R6
bne L2
move.l #$80000000,_ldivr
move.l #$80000000,R0
bra L1
L2:
bge L3
neg.l R6
add #1,R3
L3:
tst.l R7
bge L4
neg.l R7
add #1,R3
L4:
cmp.l R7,R6
bgt L6
bne L7
move.l #1,R5
clr.l R7
bra L6
L7:
cmp.l #$10000,R7
bge L9
divu R6,R7
move R7,R5
swap R7
ext.l R7
bra L6
L9:
move.l #1,R4
L12:
cmp.l R6,R7
blo L11
asl.l #1,R6
asl.l #1,R4
bra L12
L11:
tst.l R4
beq L6
cmp.l R6,R7
blo L15
or.l R4,R5
sub.l R6,R7
L15:
lsr.l #1,R4
lsr.l #1,R6
bra L11
L6:
cmp #1,R3
bne L16
neg.l R7
move.l R7,_ldivr
move.l R5,R0
neg.l R0
bra L1
L16:
move.l R7,_ldivr
move.l R5,R0
L1:
tst.l (sp)+
movem.l (sp)+,R3-R7
unlk R14
rts

View File

@@ -0,0 +1,12 @@
__length(s)
char *s;
{
register int l;
register char *p;
p = s;
l = 0;
while (*p++)
l++;
return(l);
}

View File

@@ -0,0 +1,74 @@
*// long multiply routine without floating point
*// call with:
*// two long values on stack
*// returns:
*// long value in R0 and R1
*//
*// warning: no overflow checking or indication!!!!
*struct {
* int hiword;
* int loword;
*};
*long lmul(l1,l2)
*long l1,l2;
*{
*
* long t1;
* register int sign;
* register int t2;
*
* sign = 0;
* if(l1 < 0) {
* l1 = -l1; //make it positive
* sign++;
* }
* if(l2 < 0) {
* l2 = -l2; //make it positive
* sign++;
* }
* t1 = l1.loword*l2.loword;
* t2 = l1.hiword*l2.loword + l2.hiword*l1.loword;
* t1.hiword = t1.hiword + t2;
* if(sign&1)
* t1 = -t1; //negate results
* return(t1);
*}
*
*
.globl lmul
.text
lmul:
_lmul:
~~lmul:
~sign=R2
~l1=8
~l2=12
~t1=-4
~t2=R6
link R14,#-4
clr R2
tst.l 8(R14) //is first arg negative?
bge L2
neg.l 8(R14) //yes, negate it
inc R2 // increment sign flag
L2:tst.l 12(R14) //is second arg negative?
bge L3
neg.l 12(R14) //yes, make it positive
inc R2 //increment sign flag
L3:move 10(R14),R0 //arg1.loword
mulu 14(R14),R0 //arg2.loword
move.l R0,-4(R14) //save in temp
move 8(R14),R0 //arg1.hiword
mulu 14(R14),R0 //arg2.loword
move 12(R14),R1 //arg2.hiword
mulu 10(R14),R1 //arg1.loword
add R1,R0 //form the sum of 2 lo-hi products
add -4(R14),R0 //add to temp hiword
move R0,-4(R14) //store back in temp hiword
move.l -4(R14),R0 //long results
btst #0,R2 //test sign flag
beq L4
neg.l R0 //complement the results
L4:
unlk R14
rts

View File

@@ -0,0 +1,19 @@
.globl _ldiv
.globl _ldivr
.comm _ldivr,4
.globl _lrem
.globl lrem
.text
_lrem:
lrem:
~~lrem:
~l2=12
~al1=8
link R14,#-2
move.l 12(R14),-(sp)
move.l 8(R14),-(sp)
jsr _ldiv
cmpm.l (sp)+,(sp)+
move.l _ldivr,R0
unlk R14
rts

View File

@@ -0,0 +1,12 @@
rm lib7.a
ar r lib7.a \
printf.o \
__prtint.o \
__length.o \
lrem.o \
ldiv.o \
lmul.o \
exit.o \
cputc.o \
getchar.o \
putchar.o

View File

@@ -0,0 +1,26 @@
* write one char to the crt
* call with: ascii char to write in D0
status1: .equ $3ff01 //really $3ff01
port1: .equ $3ff03 //really $3ff03
.globl _putchar
.text
_putchar:
move.l (sp)+,A1 //return address
move (sp),R0 //char to send
cmp.b #9,R0 //tab?
bne l11
move.b #' ',R0 //make it space
l11:
move #1,R1
move.l #status1,A0
loop1: btst R1,(A0) //test transmitter empty
beq loop1 //not empty
move.b R0,2(A0) //send char
cmp.b #$0a,R0 //line feed?
bne l0
move.b #$0d,R0 //carriage return
bra loop1
l0:
jmp (A1) //return
.end

View File

@@ -0,0 +1,275 @@
# include "iodec.h"
# define BUFSIZ 80
/**
** formated print
**/
printf(parlist)
char *parlist;
{
register char *fmt, c;
char buf[BUFSIZ];
extern char *__prtshort(), *__prtld(), *__prtld();
// double *dblptr;
int mode;
char *fd;
register char **p;
register int *pi;
int width, prec;
int left, longf;
char padchar;
char *s;
int n;
auto (*fn)();
int len;
p = &parlist;
fd = 0;
mode = 0; /* mode zero, putchar */
if (parlist + 1 < MAXFILES + 1)
{
mode++; /* mode one, cputc */
fd = *p++;
}
if (fd == -1)
{
mode++; /* mode two, string */
fd = *p++;
}
fmt = *p++;
pi = p;
while (c = *fmt++)
{
p = pi;
if (c != '%')
{
__putch(mode, &fd, c);
continue;
}
left = 0;
if ((c = *fmt++) == '-')
{
c = *fmt++;
left++;
}
padchar = ' ';
if (c == '0')
{
padchar = c;
c = *fmt++;
}
width = -1;
while (c >= '0' && c <= '9')
{
if (width < 0)
width = 0;
width = width * 10 + (c - '0');
c = *fmt++;
}
prec = -1;
if (c == '.')
{
prec = 0;
c = *fmt++;
}
while (c >= '0' && c <= '9')
{
prec = prec * 10 + (c - '0');
c = *fmt++;
}
longf = 0;
if (c == 'l')
{
longf++;
c = *fmt++;
}
/* we now have all the prelims out of the way;
let's see what we want to print */
s = buf;
switch (c)
{
case 'd': /* decimal signed */
case 'D':
if (longf)
fn = __prtld;
else
fn = __prtshort;
__prtint(pi++, buf, 10, 1, fn, 0);
if (longf)
pi++;
break;
case 'u': /* decimal unsigned */
case 'U':
__prtint(pi++, buf, 10, 0, __prtshort, 0);
break;
case 'o': /* octal unsigned */
case 'O':
if (longf)
fn = __prtld;
else
fn = __prtshort;
__prtint(pi++, buf, 8, 0, fn, 0);
if (longf)
pi++;
break;
case 'x': /* hexadecimal unsigned */
case 'X':
if (longf)
fn = __prtld;
else
fn = __prtshort;
__prtint(pi++, buf, 16, 0, fn, c == 'X');
if (longf)
pi++;
break;
case 's': /* string */
case 'S':
s = *p++;
pi = p;
break;
case 'c': /* character */
case 'C':
n = *pi++;
buf[0] = n;
buf[1] = '\0';
break;
// case 'e': /* exponential */
// case 'E':
// case 'f': /* floating */
// case 'F':
// case 'g': /* e or f */
// case 'G':
// case 'n':
// case 'N':
// dblptr = p;
// if (prec < 0)
// prec = 7;
// ftoa(*dblptr, buf, sizeof buf - 1, prec, c);
// while (*s == ' ')
// s++;
// p =+ 4;
// prec = -1;
// break;
default: /* just print the character */
__putch(mode, &fd, c);
continue;
}
len = __length(s);
if (prec < len && prec >= 0)
len = prec;
n = width - len;
if (!left)
{
if (padchar != ' ' && *s == '-')
{
len--;
__putch(mode, &fd, *s++);
}
while (n-- > 0)
__putch(mode, &fd, padchar);
}
while (len--)
__putch(mode, &fd, *s++);
while (n-- > 0)
__putch(mode, &fd, padchar);
}
if (mode == 2)
*fd = '\0';
}
__putch(mode, pfd, c)
int mode;
char c;
char **pfd;
{
switch (mode)
{
case 0:
putchar(c);
break;
case 1:
cputc(c, *pfd);
break;
case 2:
*(*pfd)++ = c;
break;
}
return (c);
}
char *__prtld(pobj, pbuf, base, signed, digs)
long *pobj;
char **pbuf;
int base;
int signed;
char *digs;
{
register long n;
register long b;
register char *p;
struct {
char cbyte0;
char cbyte1;
char cbyte2;
char cbyte3;
};
extern long ldiv();
extern long ldivr;
register i;
struct {
int wd1;
int wd2;
};
p = digs;
b = base;
n = *pobj;
if(base == 16) { //special because of negatives
i = 8;
while(n && i) {
*p++ = n & 0xf;
n =>> 4;
i--;
}
}
else if(base == 8) {
i = 11;
while(n && i) {
*p++ = n & 7;
n =>> 3;
i--;
}
if(i==0) {
*(p-1) =& 3; //only 2 bits in upper octal digit
}
}
else {
if (signed && n < 0) {
*(*pbuf)++ = '-';
n = -n;
}
while(n) {
n = ldiv(n,b);
*p++ = ldivr.cbyte3;
}
}
return (p);
}

View File

@@ -0,0 +1,62 @@
char *__prtint(pobj, buf, base, signed, f, upper)
int *pobj;
char *buf;
int base;
int signed;
int upper;
char *(*f)();
{
char digs[15];
register char *dp;
register int k;
register char *p;
dp = (*f)(pobj, &buf, base, signed, digs);
if (dp == digs)
*dp++ = 0;
p = buf;
while (dp != digs)
{
k = *--dp;
if (k < 10)
k =+ '0';
else
k =+ upper ? 'A'-10 : 'a'-10;
*p++ = k;
}
*p = 0;
return (p);
}
char *__prtshort(pobj, pbuf, base, signed, digs)
int *pobj;
char **pbuf;
int base;
int signed;
char *digs;
{
extern long ldivr;
register long n;
register char *p;
register long b;
p = digs;
b = base;
n = *pobj;
if (signed && n < 0)
{
n = -n;
*(*pbuf)++ = '-';
}
else {
n =& 0xffffL; //clear upper half
}
while (n != 0)
{
n = ldiv(n,b);
*p++ = ldivr;
}
return (p);
}

View File

@@ -0,0 +1,22 @@
* write one char to the crt
* call with: ascii char to write in D0
status1: .equ $3ff01 //really $3ff01
port1: .equ $3ff03 //really $3ff03
.globl _putchar
.text
_putchar:
move.l (sp)+,A1 //return address
move (sp),R0 //char to send
move #1,R1
move.l #status1,A0
loop1: btst R1,(A0) //test transmitter empty
beq loop1 //not empty
move.b R0,2(A0) //send char
cmp.b #$0a,R0 //line feed?
bne l0
move.b #$0d,R0 //carriage return
bra loop1
l0:
jmp (A1) //return
.end