home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
djasy10d.zip
/
DIFFS.10D
< prev
next >
Wrap
Text File
|
1992-09-11
|
10KB
|
413 lines
diff -bBd async.100/async.c async/async.c
0a1,4
> /* async.c -- dj's async interface, modified for two ports and
> pointer-bashing protection by j. alan eldridge 09/04/92
> */
>
1a6
> #include <stdlib.h>
3a9,10
> #include "djasync.h"
>
10a18,23
> #define disable() asm("cli")
> #define enable() asm("sti")
> #endif
>
> #ifdef __TURBOC__
> #include <conio.h>
12a26,28
> #define NO_INTR 1
> #define RDY_CNT 1
>
21a38,41
> short count;
> short overflow;
> short buffer_size;
> short ovflushes;
24,33c44,45
< static ASYNC_STRUCT far *async;
< static int iov;
< #define com_rb iov
< #define com_tb iov
< #define com_ier iov+1
< #define com_ifr iov+2
< #define com_bfr iov+3
< #define com_mcr iov+4
< #define com_lsr iov+5
< #define com_msr iov+6
---
> static ASYNC_STRUCT far *async[2];
> static int iov[2];
35c47,56
< char far *aptr(short p)
---
> #define com_rb(n) iov[n]
> #define com_tb(n) iov[n]
> #define com_ier(n) iov[n]+1
> #define com_ifr(n) iov[n]+2
> #define com_bfr(n) iov[n]+3
> #define com_mcr(n) iov[n]+4
> #define com_lsr(n) iov[n]+5
> #define com_msr(n) iov[n]+6
>
> static char far *aptr(int port, short p)
38c59
< return (char *)((unsigned)async - OFFSET + p);
---
> return (char *)((unsigned)async[port] - OFFSET + p);
40c61
< return (char far *)MK_FP(FP_SEG(async), p);
---
> return (char far *)MK_FP(FP_SEG(async[port]), p);
44c65
< ASYNC_STRUCT far *getivec(int which)
---
> static ASYNC_STRUCT far *getivec(int which)
61c82
< async_init()
---
> int async_init(int port)
63,79c84,86
< ASYNC_STRUCT far *a1;
< ASYNC_STRUCT far *a2;
< a1 = getivec(12);
< a2 = getivec(11);
< async = 0;
< if (a1)
< async = a1;
< if (a2)
< async = a2;
< if (a1 && a2)
< {
< if (a1 < a2)
< async = a1;
< else
< async = a2;
< }
< if (async == 0)
---
> async[port] = getivec(12-port);
>
> if (!async[port])
82c89
< exit(1);
---
> return 0;
84,87c91,95
< iov = async->iov;
< outportb(com_ier, 0x0f);
< outportb(com_bfr, 0x03);
< outportb(com_mcr, 0x0b);
---
> iov[port] = async[port]->iov;
> outportb(com_ier(port), 0x0f);
> outportb(com_bfr(port), 0x03);
> outportb(com_mcr(port), 0x0b);
> return 1;
90c98
< async_tx(char c)
---
> int async_cnt(int port)
92,93c100
< while (~inportb(com_lsr) & 0x20);
< outportb(com_tb, c);
---
> return async[port]->count;
96c103
< int async_ready()
---
> void async_flush(int port)
98c105,108
< return (async->getp != async->putp);
---
> disable();
> async[port]->count = async[port]->overflow = 0;
> async[port]->getp = async[port]->putp = async[port]->buffer_start;
> enable();
101c111,147
< int async_rx()
---
> int async_overflow(int port)
> {
> int ret;
>
> disable();
> ret = async[port]->overflow;
> async[port]->overflow = 0;
> enable();
>
> return ret;
> }
>
>
> int async_tx(int port, char c)
> {
> while (~inportb(com_lsr(port)) & 0x20);
> outportb(com_tb(port), c);
>
> return 0;
> }
>
> int async_ready(int port)
> {
> int ret;
>
> disable();
> #if RDY_CNT
> ret = async[port]->count;
> #else
> ret = (async[port]->getp != async[port]->putp);
> #endif
> enable();
>
> return ret;
> }
>
> int async_rx(int port)
104,107c150,160
< while (!async_ready);
< rv = *aptr(async->getp++);
< if (async->getp >= async->buffer_end)
< async->getp = async->buffer_start;
---
>
> while (!async_ready(port))
> /* spin wheels */;
>
> disable();
> rv = *aptr(port, async[port]->getp++);
> async[port]->count--;
> if (async[port]->getp >= async[port]->buffer_end)
> async[port]->getp = async[port]->buffer_start;
> enable();
>
diff -bBd async.100/asynctsr.asm async/asynctsr.asm
4a5,6
> BUFSIZE = 4096
>
13c15
< buffer_end equ buffer_start+500
---
> buffer_end equ buffer_start+BUFSIZE
20,21c22,23
< dw offset buffer_start
< dw offset buffer_end
---
> bbeg dw offset buffer_start
> bend dw offset buffer_start
24a27,30
> count dw 0
> over dw 0
> bsize dw BUFSIZE
> flush dw 1
60,64c66,90
< mov cs:[bx],al
< inc bx
< cmp bx,offset buffer_end
< jb isr_noend
< mov bx,offset buffer_start
---
> mov cx,count
> ; check for & handle buffer overflow <jae>
> cmp cx,bsize
> jb isr_addch ; count < bsize ==> ok
> inc over ; count the overflow
> isr_ckflush:
> cmp flush,0
> jg isr_flush
> dec cx ; dec count (in cx)
> dec bx ; back up putp (in bx)
> cmp bx,offset buffer_start ; fell off start of buffer?
> jge isr_addch ; no, go ahead
> mov bx,bend ; yes, wrap to end of buffer - 1
> dec bx
> jmp isr_addch
> isr_flush:
> xor cx, cx
> ; end of overflow handling <jae>
> isr_addch:
> inc cx ; count new char
> mov cs:[bx],al ; save it at putp
> inc bx ; inc putp
> cmp bx,bend ; fell off end of buffer?
> jb isr_noend ; no, go ahead
> mov bx,offset buffer_start ; yes, wrap to start of buffer
66c92,93
< mov putp,bx
---
> mov putp,bx ; save off new putp
> mov count,cx ; save off new count
76a104,108
> err1 db 'Usage: asynctsr 1|2 [-][nnnn]',13,10
> db ' - no-flush-on-overflow flag (opt)',13,10
> db ' nnnn receive buffer size (opt,default=4096)'
> db 13,10,'$'
>
82a115
> cmderr:
89,90d121
< err1 db 'Usage: asynctsr 1|2',13,10,'$'
<
91a123
> call parse
97a130
> call parse
104a138
> cli
106a141
> sti
123c158,160
< mov dx,offset buffer_end
---
> mov dx,offset buffer_start
> add dx,[bsize]
> mov [bend], dx
127a165,208
> parse: ; parse the buffer size from the command line
> mov cl, ds:[80h];
> cmp cl, 3
> jl endparse
> mov si, 83h
> lodsb
> cmp al,' '
> jne errparse
> mov al,[si]
> cmp al,'-'
> jne goparse
> mov flush,0
> dec cl
> inc si
> goparse:
> sub cl, 3
> je endparse
> xor dx, dx
> xor bh, bh
> xor ax, ax
> mov di, 10
> get1:
> mov bl,ds:[si]
> inc si
> dec cl
> cmp bl,'0'
> jl errparse
> cmp bl,'9'
> jg errparse
> sub bl,'0'
> imul di
> add ax,bx
> cmp cl, 0
> jg get1
> setsize:
> or ax,ax
> je endparse
> mov bsize,ax
> endparse:
> ret
>
> errparse:
> jmp cmderr
>
Binary files async.100/asynctsr.com and async/asynctsr.com differ
diff -bBd async.100/atest.c async/atest.c
1a2
> #include <stdlib.h>
2a4,6
> #include <io.h>
>
> #include "djasync.h"
5c9,11
< #define getch getkey
---
> #include <gppconio.h>
> #else
> #include <conio.h>
8c14,16
< main()
---
> #include <dos.h>
>
> main(int ac, char** av)
10c18,24
< async_init();
---
> int port = ac > 1 ? atoi(av[1]) - 1 : 0;
> int show = ac > 2;
> int msec = ac > 2 ? atoi(av[2]) : 0;
>
> if (!async_init(port))
> return 1;
>
12a27,28
> int x,y;
>
18c34
< async_tx(ch);
---
> async_tx(port,ch);
20c36,47
< if (async_ready())
---
>
> if (show) {
> if (msec)
> delay(msec);
> x=wherex();
> y=wherey();
> gotoxy(1,1);
> cprintf("%04d %04d",async_cnt(port),async_overflow(port));
> gotoxy(x,y);
> }
>
> if (async_ready(port))
22c49
< char c = async_rx();
---
> char c = async_rx(port);
25a53
> return 0;
Binary files async.100/atest.exe and async/atest.exe differ
Only in async: atestpp.cc
Only in async: atestpp.exe
Only in async: diffs.10c
Only in async: djasync.h
Binary files async.100/gtest and async/gtest differ
Only in async: gtestpp
diff -bBd async.100/makefile async/makefile
1c1,5
< all : asynctsr.com atest.exe gtest
---
> all: asynctsr.com atest.exe gtest atestpp.exe gtestpp
>
> # if you have Turbo C++, use tcc instead
> CC=bcc -v -c-
> GCC=gcc -g -O2
4,6c8,9
< masm asynctsr;
< tlink asynctsr;
< exe2bin asynctsr.exe asynctsr.com
---
> tasm asynctsr;
> tlink /t asynctsr;
8,9c11,12
< atest.exe : atest.obj async.obj
< tcc atest.obj async.obj
---
> atest.exe : atest.c async.c
> $(CC) atest.c async.c
11,12c14,23
< gtest : atest.o async.o
< gcc -o gtest atest.o async.o -lpc
---
> gtest : atest.c async.c
> $(GCC) -o gtest atest.c async.c -lpc
>
> atestpp.exe : atestpp.cc async.c
> copy atestpp.cc atestpp.cpp
> $(CC) atestpp.cpp async.c
> del atestpp.cpp
>
> gtestpp : atestpp.cc async.c
> $(GCC) -o gtestpp atestpp.cc async.c -lpc
Only in async: readme.jae