1
0
mirror of https://github.com/DoctorWkt/pdp7-unix.git synced 2026-01-26 04:02:27 +00:00

Progress on B stuff

Setup argv array based on Phil Budne's assembly.  Added string and ctype
libraries (untested).
This commit is contained in:
rswier
2016-04-01 03:50:19 -04:00
parent 208ed1dbf5
commit 22f0d2e99a
5 changed files with 126 additions and 25 deletions

View File

@@ -230,29 +230,23 @@ flush: 0
jmp flush i
initio: 0
law .argv " build argument list
dac 8 " auto-inc pointer argvp = &argv[-1]
lac 017777 i
" sad d4
jmp 2f
sad d8
jmp 1f
cll rtr
dac 8 i " *++argvp = arg count
cma
tad d1
dac t1 " count = -argv[0]
lac 017777
dac lastv " set top of heap
tad d1 " ac = addr of arg0
1:
dac 8 i " *++argvp = ac
tad d4 " ac += 4
isz t1 " while ++count != 0
jmp 1b
law 9
tad 017777
dac .+3
law 017
sys creat; ..
spa
jmp stop
dac .fout
1:
law 5
tad 017777
dac .+2
sys open; ..; 0
spa
jmp stop
dac .fin
2:
lac lastv
dac eibufp
dac cibufp
@@ -280,7 +274,7 @@ iflg: 0
eobufp: 0
cobufp: 0
oflg: 0
lastv: 017770
lastv: 0
o777: 0777
d4:o4: 4

View File

@@ -2,12 +2,25 @@
char(s, n) {
if (n & 1) return(s[n/2] & 0777);
return ((s[n/2]/512) & 0777);
return((s[n/2]/512) & 0777);
}
lchar(s, n, c) {
if (n & 1) s[n/2] = (s[n/2] & 0777000) | c;
else s[n/2] = (s[n/2] & 0777) | (c*512);
return(c);
}
getstr(s) {
auto c, i;
i = 0;
while ((c = getchr()) != '*n') {
lchar(s,i,c);
i = i+1;
}
lchar(s,i,'*e');
return(s);
}
putstr(s) {

9
src/other/ctype.b Normal file
View File

@@ -0,0 +1,9 @@
/* ctype.b - character types */
isalpha(c) {
return((c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z'));
}
isdigit(c) {
return(c >= '0' & c <= '9');
}

58
src/other/string.b Normal file
View File

@@ -0,0 +1,58 @@
/* string.b - B string library
mostly from: https://www.bell-labs.com/usr/dmr/www/btut.html
*/
strcopy(sl, s2) {
auto i;
i = 0;
while (lchar(sl,i,char(s2,i)) != '*e')
i = i+1;
return(s1);
}
strcat(s1, s2) {
auto i,j;
i = j = 0;
while (char(s1,i) != '*e')
i = i+1;
while(lchar(s1,i,char(s2,j)) != '*e') {
i = i+1;
j = j+1;
}
return(s1);
}
strlen(s) {
auto i;
i = 0;
while (char(s,i) != '*e')
i = i+1;
return(i);
}
strcmp(s1, s2) {
auto c,i;
i = 0;
while ((c=char(s1,i)) == char(s2,i)) {
if (c == '*e')
return(0);
i = i+1;
}
return(c - char(s2,i));
}
/* convert command line argument into a string */
strarg(s, a) {
auto i, c;
i = 0;
while (i < 8) {
if ((c = char(a,i)) == ' ')
goto done;
lchar(s,i,c);
i = i+1;
}
done:
lchar(s,i,'*e');
return(s);
}

View File

@@ -7,14 +7,41 @@
perl a7out test.out
*/
/* convert command line argument into a string */
strarg(s, a) {
auto i, c;
i = 0;
while (i < 8) {
if ((c = char(a,i)) == ' ')
goto done;
lchar(s,i,c);
i = i+1;
}
done:
lchar(s,i,'*e');
return(s);
}
main {
extrn fname, fin;
auto ch,p;
extrn fname, fin, fout, argv;
auto ch,p,n,str 5;
p = 017777;
printf("mem[0%o] = 0%o*n",p,*p);
printf("mem[0%o] = %d*n",*p,**p);
printf("argv = %d*n",argv);
printf("**argv = %d*n",*argv);
printf("argv[0] = %d*n",argv[0]);
n = 0;
while (n < argv[0]) {
n = n+1;
printf("argv[%d] = 0%o *"%s*"*n",n,argv[n],strarg(str,argv[n]));
}
printf("array(0) = 0%o*n",array(0));
printf("array(64) = 0%o*n",array(64));
printf("array(0) = 0%o*n",array(0));
/* fin = open(fname, 0); */
fin = open("abc ", 0);