home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / djasy10d.zip / DIFFS.10D < prev    next >
Text File  |  1992-09-11  |  10KB  |  413 lines

  1. diff -bBd async.100/async.c async/async.c
  2. 0a1,4
  3. > /*  async.c -- dj's async interface, modified for two ports and
  4. >     pointer-bashing protection by j. alan eldridge 09/04/92
  5. > */
  6. 1a6
  7. > #include <stdlib.h>
  8. 3a9,10
  9. > #include "djasync.h"
  10. 10a18,23
  11. > #define disable() asm("cli")
  12. > #define enable() asm("sti")
  13. > #endif
  14. > #ifdef __TURBOC__
  15. > #include <conio.h>
  16. 12a26,28
  17. > #define NO_INTR 1
  18. > #define RDY_CNT 1
  19. 21a38,41
  20. >   short count;
  21. >   short overflow;
  22. >   short buffer_size;
  23. >   short ovflushes;
  24. 24,33c44,45
  25. < static ASYNC_STRUCT far *async;
  26. < static int iov;
  27. < #define com_rb    iov
  28. < #define com_tb    iov
  29. < #define com_ier    iov+1
  30. < #define com_ifr    iov+2
  31. < #define com_bfr    iov+3
  32. < #define com_mcr    iov+4
  33. < #define com_lsr    iov+5
  34. < #define com_msr    iov+6
  35. ---
  36. > static ASYNC_STRUCT far *async[2];
  37. > static int              iov[2];
  38. 35c47,56
  39. < char far *aptr(short p)
  40. ---
  41. > #define com_rb(n)    iov[n]
  42. > #define com_tb(n)    iov[n]
  43. > #define com_ier(n)    iov[n]+1
  44. > #define com_ifr(n)    iov[n]+2
  45. > #define com_bfr(n)    iov[n]+3
  46. > #define com_mcr(n)    iov[n]+4
  47. > #define com_lsr(n)    iov[n]+5
  48. > #define com_msr(n)    iov[n]+6
  49. > static char far *aptr(int port, short p)
  50. 38c59
  51. <   return (char *)((unsigned)async - OFFSET + p);
  52. ---
  53. >   return (char *)((unsigned)async[port] - OFFSET + p);
  54. 40c61
  55. <   return (char far *)MK_FP(FP_SEG(async), p);
  56. ---
  57. >   return (char far *)MK_FP(FP_SEG(async[port]), p);
  58. 44c65
  59. < ASYNC_STRUCT far *getivec(int which)
  60. ---
  61. > static ASYNC_STRUCT far *getivec(int which)
  62. 61c82
  63. < async_init()
  64. ---
  65. > int async_init(int port)
  66. 63,79c84,86
  67. <   ASYNC_STRUCT far *a1;
  68. <   ASYNC_STRUCT far *a2;
  69. <   a1 = getivec(12);
  70. <   a2 = getivec(11);
  71. <   async = 0;
  72. <   if (a1)
  73. <     async = a1;
  74. <   if (a2)
  75. <     async = a2;
  76. <   if (a1 && a2)
  77. <   {
  78. <     if (a1 < a2)
  79. <       async = a1;
  80. <     else
  81. <       async = a2;
  82. <   }
  83. <   if (async == 0)
  84. ---
  85. >   async[port] = getivec(12-port);
  86. >   if (!async[port])
  87. 82c89
  88. <     exit(1);
  89. ---
  90. >     return 0;
  91. 84,87c91,95
  92. <   iov = async->iov;
  93. <   outportb(com_ier, 0x0f);
  94. <   outportb(com_bfr, 0x03);
  95. <   outportb(com_mcr, 0x0b);
  96. ---
  97. >   iov[port] = async[port]->iov;
  98. >   outportb(com_ier(port), 0x0f);
  99. >   outportb(com_bfr(port), 0x03);
  100. >   outportb(com_mcr(port), 0x0b);
  101. >   return 1;
  102. 90c98
  103. < async_tx(char c)
  104. ---
  105. > int async_cnt(int port)
  106. 92,93c100
  107. <   while (~inportb(com_lsr) & 0x20);
  108. <   outportb(com_tb, c);
  109. ---
  110. >     return async[port]->count;
  111. 96c103
  112. < int async_ready()
  113. ---
  114. > void async_flush(int port)
  115. 98c105,108
  116. <   return (async->getp != async->putp);
  117. ---
  118. >     disable();
  119. >     async[port]->count = async[port]->overflow = 0;
  120. >     async[port]->getp = async[port]->putp = async[port]->buffer_start;
  121. >     enable();
  122. 101c111,147
  123. < int async_rx()
  124. ---
  125. > int async_overflow(int port)
  126. > {
  127. >     int ret;
  128. >     
  129. >     disable();
  130. >     ret = async[port]->overflow;
  131. >     async[port]->overflow = 0;
  132. >     enable();
  133. >     return ret;
  134. > }
  135. > int async_tx(int port, char c)
  136. > {
  137. >   while (~inportb(com_lsr(port)) & 0x20);
  138. >   outportb(com_tb(port), c);
  139. >   return 0;
  140. > }
  141. > int async_ready(int port)
  142. > {
  143. >   int ret;
  144. >   
  145. >   disable();
  146. > #if RDY_CNT
  147. >   ret = async[port]->count;
  148. > #else
  149. >   ret = (async[port]->getp != async[port]->putp);
  150. > #endif
  151. >   enable();
  152. >   return ret;
  153. > }
  154. > int async_rx(int port)
  155. 104,107c150,160
  156. <   while (!async_ready);
  157. <   rv = *aptr(async->getp++);
  158. <   if (async->getp >= async->buffer_end)
  159. <     async->getp = async->buffer_start;
  160. ---
  161. >   while (!async_ready(port))
  162. >       /* spin wheels */;
  163. >   disable();
  164. >   rv = *aptr(port, async[port]->getp++);
  165. >   async[port]->count--;
  166. >   if (async[port]->getp >= async[port]->buffer_end)
  167. >     async[port]->getp = async[port]->buffer_start;
  168. >   enable();
  169. diff -bBd async.100/asynctsr.asm async/asynctsr.asm
  170. 4a5,6
  171. > BUFSIZE            = 4096
  172. 13c15
  173. < buffer_end    equ    buffer_start+500
  174. ---
  175. > buffer_end      equ     buffer_start+BUFSIZE
  176. 20,21c22,23
  177. <     dw    offset buffer_start
  178. <     dw    offset buffer_end
  179. ---
  180. > bbeg    dw      offset buffer_start
  181. > bend    dw      offset buffer_start
  182. 24a27,30
  183. > count   dw      0
  184. > over    dw      0
  185. > bsize   dw      BUFSIZE
  186. > flush   dw      1
  187. 60,64c66,90
  188. <     mov    cs:[bx],al
  189. <     inc    bx
  190. <     cmp    bx,offset buffer_end
  191. <     jb    isr_noend
  192. <     mov    bx,offset buffer_start
  193. ---
  194. >         mov     cx,count
  195. >         ; check for & handle buffer overflow <jae>
  196. >         cmp     cx,bsize
  197. >         jb      isr_addch       ; count < bsize ==> ok
  198. >         inc     over            ; count the overflow
  199. > isr_ckflush:
  200. >         cmp     flush,0
  201. >         jg      isr_flush
  202. >         dec     cx              ; dec count (in cx) 
  203. >         dec     bx              ; back up putp (in bx)
  204. >         cmp     bx,offset buffer_start  ; fell off start of buffer?
  205. >         jge     isr_addch               ; no, go ahead
  206. >         mov     bx,bend                 ; yes, wrap to end of buffer - 1
  207. >         dec     bx
  208. >         jmp     isr_addch
  209. > isr_flush:
  210. >     xor    cx, cx
  211. >         ; end of overflow handling <jae>
  212. > isr_addch:
  213. >         inc     cx              ; count new char
  214. >         mov     cs:[bx],al      ; save it at putp
  215. >         inc     bx              ; inc putp
  216. >         cmp     bx,bend         ; fell off end of buffer?
  217. >         jb      isr_noend       ; no, go ahead
  218. >         mov     bx,offset buffer_start  ; yes, wrap to start of buffer
  219. 66c92,93
  220. <     mov    putp,bx
  221. ---
  222. >         mov     putp,bx         ; save off new putp
  223. >         mov     count,cx        ; save off new count
  224. 76a104,108
  225. > err1    db      'Usage: asynctsr 1|2 [-][nnnn]',13,10
  226. >         db      '    -      no-flush-on-overflow flag (opt)',13,10
  227. >         db      '    nnnn   receive buffer size (opt,default=4096)'
  228. >         db      13,10,'$'
  229. 82a115
  230. > cmderr:
  231. 89,90d121
  232. < err1    db    'Usage: asynctsr 1|2',13,10,'$'
  233. 91a123
  234. >         call    parse
  235. 97a130
  236. >         call    parse
  237. 104a138
  238. >         cli
  239. 106a141
  240. >         sti
  241. 123c158,160
  242. <     mov    dx,offset buffer_end
  243. ---
  244. >         mov     dx,offset buffer_start
  245. >         add     dx,[bsize]
  246. >         mov     [bend], dx
  247. 127a165,208
  248. > parse:  ; parse the buffer size from the command line
  249. >         mov     cl, ds:[80h];
  250. >         cmp     cl, 3
  251. >         jl      endparse
  252. >         mov     si, 83h
  253. >         lodsb   
  254. >         cmp     al,' '
  255. >         jne     errparse
  256. >         mov     al,[si]
  257. >         cmp     al,'-'
  258. >         jne     goparse
  259. >         mov     flush,0
  260. >         dec     cl
  261. >         inc     si
  262. > goparse:
  263. >         sub     cl, 3
  264. >         je      endparse
  265. >         xor     dx, dx
  266. >         xor     bh, bh
  267. >         xor     ax, ax
  268. >         mov     di, 10
  269. > get1:
  270. >         mov     bl,ds:[si]
  271. >         inc     si
  272. >         dec     cl
  273. >         cmp     bl,'0'
  274. >         jl      errparse
  275. >         cmp     bl,'9'
  276. >         jg      errparse
  277. >         sub     bl,'0'
  278. >         imul    di
  279. >         add     ax,bx
  280. >         cmp     cl, 0
  281. >         jg      get1
  282. > setsize:        
  283. >         or      ax,ax
  284. >         je      endparse
  285. >         mov     bsize,ax
  286. > endparse:
  287. >         ret
  288. > errparse:
  289. >         jmp     cmderr
  290. Binary files async.100/asynctsr.com and async/asynctsr.com differ
  291. diff -bBd async.100/atest.c async/atest.c
  292. 1a2
  293. > #include <stdlib.h>
  294. 2a4,6
  295. > #include <io.h>
  296. > #include "djasync.h"
  297. 5c9,11
  298. < #define getch getkey
  299. ---
  300. > #include    <gppconio.h>
  301. > #else
  302. > #include    <conio.h>
  303. 8c14,16
  304. < main()
  305. ---
  306. > #include    <dos.h>
  307. > main(int ac, char** av)
  308. 10c18,24
  309. <   async_init();
  310. ---
  311. >   int port = ac > 1 ? atoi(av[1]) - 1 : 0;
  312. >   int show = ac > 2;
  313. >   int msec = ac > 2 ? atoi(av[2]) : 0;
  314. >     
  315. >   if (!async_init(port))
  316. >       return 1;
  317. 12a27,28
  318. >     int x,y;
  319. 18c34
  320. <       async_tx(ch);
  321. ---
  322. >       async_tx(port,ch);
  323. 20c36,47
  324. <     if (async_ready())
  325. ---
  326. >     if (show) {
  327. >         if (msec)
  328. >             delay(msec);
  329. >         x=wherex();
  330. >         y=wherey();
  331. >         gotoxy(1,1);
  332. >         cprintf("%04d %04d",async_cnt(port),async_overflow(port));
  333. >         gotoxy(x,y);
  334. >     }
  335. >         
  336. >     if (async_ready(port))
  337. 22c49
  338. <       char c = async_rx();
  339. ---
  340. >       char c = async_rx(port);
  341. 25a53
  342. >   return 0;
  343. Binary files async.100/atest.exe and async/atest.exe differ
  344. Only in async: atestpp.cc
  345. Only in async: atestpp.exe
  346. Only in async: diffs.10c
  347. Only in async: djasync.h
  348. Binary files async.100/gtest and async/gtest differ
  349. Only in async: gtestpp
  350. diff -bBd async.100/makefile async/makefile
  351. 1c1,5
  352. < all : asynctsr.com atest.exe gtest
  353. ---
  354. > all: asynctsr.com atest.exe gtest atestpp.exe gtestpp
  355. > # if you have Turbo C++, use tcc instead
  356. > CC=bcc -v -c-
  357. > GCC=gcc -g -O2
  358. 4,6c8,9
  359. <     masm asynctsr;
  360. <     tlink asynctsr;
  361. <     exe2bin asynctsr.exe asynctsr.com
  362. ---
  363. >     tasm asynctsr;
  364. >     tlink /t asynctsr;
  365. 8,9c11,12
  366. < atest.exe : atest.obj async.obj
  367. <     tcc atest.obj async.obj
  368. ---
  369. > atest.exe : atest.c async.c
  370. >     $(CC) atest.c async.c
  371. 11,12c14,23
  372. < gtest : atest.o async.o
  373. <     gcc -o gtest atest.o async.o -lpc
  374. ---
  375. > gtest : atest.c async.c
  376. >     $(GCC) -o gtest atest.c async.c -lpc
  377. > atestpp.exe : atestpp.cc async.c
  378. >         copy atestpp.cc atestpp.cpp
  379. >     $(CC) atestpp.cpp async.c
  380. >         del atestpp.cpp
  381. > gtestpp : atestpp.cc async.c
  382. >     $(GCC) -o gtestpp atestpp.cc async.c -lpc
  383. Only in async: readme.jae
  384.