Mercurial > hg > Members > kono > os9 > sbc09
changeset 132:36000611014b
micro-c buffering
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Jan 2019 19:57:11 +0900 |
parents | 188111be26b4 |
children | 2562c18c904e |
files | TL1/TL1os9.asm os9/mc09/crtos9.asm os9/mc09/makefile os9/mc09/mc.c os9/mc09/mclibos9.c os9/mc09/test/cp.c |
diffstat | 6 files changed, 121 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/TL1/TL1os9.asm Sat Jan 05 22:10:20 2019 +0900 +++ b/TL1/TL1os9.asm Sun Jan 06 19:57:11 2019 +0900 @@ -348,7 +348,7 @@ FDB $33D7 FCB WT2 FDB $33D7 - FCB WT1 $9E,WT2 + FCB WT1,$9E,WT2 FDB $A700 CLR INDEX RTS @@ -402,7 +402,7 @@ LDA #$64 do LBSR CHECK BSR ASTOUT - LDD #$3402 pshs a + LDD #$3402 pshs a LBSR PUTAB CLR INDEX LBSR STAT @@ -867,10 +867,10 @@ OLOAD LDA LSW BEQ RTE LDA ACC - BEQ *+6 - LDA #$36 - BSR PUTA1 - LDA #$86 + BEQ OL1 + LDD #$3402 pshs a + LBSR PUTAB +OL1 LDA #$86 OCORD PSHS A CLRA STA LSW @@ -887,12 +887,12 @@ LBRA PUTAB * PUT 'TAB:PULS A' PUTPUL LBSR PUTHS - FCB 2 - FDB $1632 + FCB 4 + FCB $1f,$89,$35,2 tfr a,b ; puls a RTE1 RTS * PUT 'PULS B' -PUTPLB LDA #$33 - BRA PUTA1 +PUTPLB LDA #$3504 puls b + LBRA PUTAB ** * ADDING EXPRESSION ** @@ -1041,8 +1041,8 @@ OLP LBSR OLOAD LDB ACC BEQ RTS4 - LDA #$36 - LBSR PUTA + LDD #$3402 pshs a + LBSR PUTAB CLR ACC RTS4 RTS ** FUNCTION RND
--- a/os9/mc09/crtos9.asm Sat Jan 05 22:10:20 2019 +0900 +++ b/os9/mc09/crtos9.asm Sun Jan 06 19:57:11 2019 +0900 @@ -41,7 +41,7 @@ bcc __0C005 ldd ,s subd #$1000 - blo exit can't get any memroy + lblo exit can't get any memroy std ,s bra __0C004 __0C005 @@ -76,7 +76,7 @@ std heapp,y LBSR _INITIALIZE call initializer LBSR _main -exit clrb +* exit clrb os9 F$Exit
--- a/os9/mc09/makefile Sat Jan 05 22:10:20 2019 +0900 +++ b/os9/mc09/makefile Sun Jan 06 19:57:11 2019 +0900 @@ -35,7 +35,7 @@ mc2.c: patch <diff_to_mc2 -o mc2.c -testcp : mc test/cp.c +testcp : mc test/cp.c crtos9.asm mclibos9.c ./mc -s -Mtestcp test/cp.c $(AS09) crtos9.asm -l c.lst -o testcp
--- a/os9/mc09/mc.c Sat Jan 05 22:10:20 2019 +0900 +++ b/os9/mc09/mc.c Sun Jan 06 19:57:11 2019 +0900 @@ -224,7 +224,7 @@ if ( (obuf = fopen(ccout,"w")) == NULL ) error(FILERR); else { /* we'l resize data area later */ - printf("\tmod _eom,_name,_tylg,_atrv,_start,1024\n"); /* os9 module header */ + printf("\tmod _eom,_name,_tylg,_atrv,_start,4096\n"); /* os9 module header */ printf("_name fcs /%s/\n\tfcb 0\n",modname); } }
--- a/os9/mc09/mclibos9.c Sat Jan 05 22:10:20 2019 +0900 +++ b/os9/mc09/mclibos9.c Sun Jan 06 19:57:11 2019 +0900 @@ -4,17 +4,16 @@ int errno = 0; typedef struct { - int fd; /* 0 */ - int fmode; /* 2 */ - int len; /* 4 */ - char *fname; /* 6 */ - /* - char *ptr; /* 8 - char buff[256]; /* 10/ - */ + int fd; /* 0 */ + int fmode; /* 2 */ + char length; /* 4 */ + char *fname; /* 6 */ + char *ptr; /* 8 */ + char *buf; /* 10 */ } FILE ; #define FCBSIZE (sizeof(FILE)) +#define BUFSIZ 256 #define NFILES 8 @@ -29,20 +28,16 @@ FILE _s0[3]; -#define STDIN (&_s0[0]) -#define STDOUT (&_s0[1]) -#define STDERR (&_s0[2]) - _main(prog,args) char *prog; char *args; {int i; char **argv,*p,*q; int argc,n,quote,c; - stdin = STDIN; stdin->fd = 0; - stdout = STDOUT; stdout->fd = 1; - stderr = STDERR; stderr->fd = 2; initheap(); + stdin = malloc(sizeof(FILE)*3); initfp(stdin,0); + stdout = (FILE*)(((char*)stdin)+sizeof(FILE)); initfp(stdout,1); + stderr = (FILE*)(((char*)stdout)+sizeof(FILE)); initfp(stderr,2); for ( i = 3; i < NFILES; i++ ) _fcbtbl[i] = NULL; /* create argv here */ argc = 0; @@ -82,7 +77,32 @@ argc = n; } argv[n]=0; - main(argc,argv); + exit(main(argc,argv)); +} + + +exit(e) +int e; +{ + int i; + for ( i = 3; i < NFILES; i++ ) { + if (_fcbtbl[i]) + fclose(_fcbtbl[i]); + } +#asm + ldb 3,u + os9 F$Exit +#endasm +} + +initfp(fp,d) +FILE *fp; +int fd; +{ + fp->fd = d; + fp->buf = (char*)malloc(BUFSIZ); + fp->ptr = fp->buf; + fp->fname = fp->length = fp->fmode = 0; } FILE *fopen(name,mode) @@ -122,7 +142,7 @@ pshs x,y,u ldx -2,u lda 7,u mode - ldx 6,x name + ldx 5,x name os9 I$Open bcs _LC0001 ldx -2,u @@ -140,9 +160,9 @@ _LC0002 puls x,y,u #endasm - if (fcbp->fd < 0 ) { errno = fcbp->fmode ; return NULL; } - /* fcbp->ptr = fcbp->buff; - fcbp->len = 0; */ + if (fcbp->fd < 0 ) { errno = fcbp->fmode ; *mfree(fcbp); return NULL; } + initfp(fcbp,i); + fcbp->fmode = cm; return (_fcbtbl[i] = fcbp); } @@ -161,7 +181,7 @@ ldx -2,u lda 7,u mode ldb #3 - ldx 6,x name + ldx 5,x name os9 I$Create bcs _LC0003 ldx -2,u @@ -179,9 +199,9 @@ _LC0004 puls x,y,u #endasm - if (fcbp->fd < 0 ) { errno = fcbp->fmode ; return NULL; } - /* fcbp->ptr = fcbp->buff; - fcbp->len = 0; */ + if (fcbp->fd < 0 ) { errno = fcbp->fmode ; mfree(fcbp); return NULL; } + initfp(fcbp,i); + fcbp->fmode = cm; return (_fcbtbl[i] = fcbp); } @@ -191,8 +211,9 @@ for ( i = 0; i < NFILES; i++ ) if ( fcbp == _fcbtbl[i] ) break; if ( i >= NFILES ) return EOF; - _fcbtbl[i] = NULL; - if ( (fcbp == STDIN) || (fcbp == STDOUT) || (fcbp == STDERR) ) return 0; + if ((fcbp->fmode&3) && fcbp->ptr!=fcbp->buf) { + fflush(fcbp); + } #asm pshs x,y,u ldx 4,u @@ -200,7 +221,9 @@ os9 I$Close puls x,y,u #endasm - mfree(fcbp); + _fcbtbl[i] = NULL; + if (fcbp->buf) mfree(fcbp->buf); + mfree(fcbp); return 0; } @@ -213,39 +236,69 @@ getc(fcbp) -char *fcbp; +FILE *fcbp; { - int c; + int len; + char *buff; + if (fcbp->buf) { + if (fcbp->ptr < fcbp->buf+fcbp->length) { + return (*fcbp->ptr++)&0xff; + } + len = BUFSIZ; fcbp->ptr = buff = fcbp->buf; + } else { + len = 1 ; fcbp->ptr = buff = &len; + } #asm pshs y - ldx 4,u + ldx 4,u FILE lda 1,x file descriptor - leax -1,u - clr -2,u - ldy #1 + ldx -4,u buf + ldy -2,u len os9 I$Read - bcc _LC0005 - ldd #-1 - std -2,u -_LC0005 + sty -2,u len puls y #endasm + if (len<=0) { fcbp->length=0; return -1; } + fcbp->length=len; + return (*fcbp->ptr++)&0xff; +} + +fflush(fcbp) +FILE *fcbp; +{ + int len; + char *buff; + if (fcbp->buf==0) + return; + len = fcbp->ptr - fcbp->buf; + if (len==0) return; + buff = fcbp->buf; +#asm + pshs y + ldx 4,u FILE + lda 1,x file descriptor + ldx -4,u + ldy -2,u + os9 I$Write + sty -2,u + puls y +#endasm + fcbp->ptr = fcbp->buf; } putc(c,fcbp) -char c,*fcbp; +char c; FILE *fcbp; { - int ret; -#asm - pshs y - ldx 6,u - lda 1,x file descriptor - leax 5,u - ldy #1 - os9 I$Write - puls y -#endasm - return c; + int len; + if (!fcbp->buf) { + fcbp->buf=&c; fcbp->ptr=fcbp->buf+1; + fflush(fcbp); + fcbp->buf = 0; + return; + } else if (fcbp->ptr >= fcbp->buf+BUFSIZ) { + fflush(fcbp); + } + *fcbp->ptr++ = c; } getchar()
--- a/os9/mc09/test/cp.c Sat Jan 05 22:10:20 2019 +0900 +++ b/os9/mc09/test/cp.c Sun Jan 06 19:57:11 2019 +0900 @@ -8,12 +8,13 @@ int c; int i; - input = STDIN; - output = STDOUT; + input = stdin; + output = stdout; i = 1; if (argv[i]) { input = fopen(argv[i++],"r"); } if (argv[i]) { output = fopen(argv[i++],"w"); } + if (input==0 || output==0) return 0; while( (c = getc(input) ) != -1) { putc(c,output); }