home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / ssl-4.1.lha / SSL / SSLExamp / TwoWindows.asm < prev   
Assembly Source File  |  1993-12-21  |  3KB  |  200 lines

  1. ; Small Test With Two Windows and Asynchronous File I/O
  2. ; (c) 1993 MJSoft System Software
  3. ; Martin Mares
  4.  
  5.     include    "ssmac.h"
  6.  
  7.     clistart
  8.  
  9. ; I/O Buffers
  10.  
  11. bufsize    equ    256
  12.  
  13.     dbuf    buf1r,bufsize
  14.     dbuf    buf2r,bufsize
  15.     dbuf    buf1w,bufsize
  16.     dbuf    buf2w,bufsize
  17.  
  18. ; Open both windows
  19.  
  20.     dv.l    file1
  21.     dv.l    file2
  22.  
  23.     dtl    <CON:0/0/640/100/First Window>,a0
  24.     move.l    #MODE_OLDFILE,d0
  25.     call    ss,TrackOpen
  26.     put.l    d0,file1
  27.  
  28.     dtl    <CON:0/100/640/100/Second Window>,a0
  29.     move.l    #MODE_OLDFILE,d0
  30.     call    TrackOpen
  31.     put.l    d0,file2
  32.  
  33. ; Create packets
  34.  
  35.     dbuf    message1r,MN_SIZE
  36.     dbuf    packet1r,dp_SIZEOF
  37.     dbuf    message2r,MN_SIZE
  38.     dbuf    packet2r,dp_SIZEOF
  39.     dbuf    message1w,MN_SIZE
  40.     dbuf    packet1w,dp_SIZEOF
  41.     dbuf    message2w,MN_SIZE
  42.     dbuf    packet2w,dp_SIZEOF
  43.  
  44.     geta    message1r,a2
  45.     moveq    #3,d7
  46.     move.l    4.w,a6
  47.     move.l    ThisTask(a6),a3
  48.     lea    pr_MsgPort(a3),a3
  49. creapack    move.b    #NT_MESSAGE,LN_TYPE(a2)
  50.     move.l    a3,MN_REPLYPORT(a2)
  51.     lea    MN_SIZE(a2),a1
  52.     move.l    a1,LN_NAME(a2)
  53.     move.l    a2,(a1)+
  54.     move.l    a3,(a1)+
  55.     lea    (MN_SIZE+dp_SIZEOF)(a2),a2
  56.     dbra    d7,creapack
  57.  
  58. ; Send both read requests before trying to receive any data
  59.  
  60.     geta    packet1r,a0
  61.     get.l    file1,d0
  62.     geta    buf1r,a2
  63.     bsr    sendreadreq
  64.  
  65.     geta    packet2r,a0
  66.     get.l    file2,d0
  67.     geta    buf2r,a2
  68.     bsr    sendreadreq
  69.  
  70. ; Wait for done packets - main loop
  71.  
  72.     moveq    #-64,d7            ; Packet flags
  73.         ; Bit 3=Write2 in progress, Bit 2=Write1
  74.         ; Bit 1=Read2, Bit 0=Read1
  75.         ; Bit 7=Stop#2, 6=Stop#1
  76. mainloop    move.l    4.w,a6
  77.     move.l    ThisTask(a6),a0
  78.     lea    pr_MsgPort(a0),a0
  79.     call    GetMsg
  80.     tst.l    d0
  81.     bne.s    packget
  82.     tst.b    d7
  83.     beq    mainend
  84.     move.l    #SIGF_DOS,d0
  85.     call    Wait
  86.     bra.s    mainloop
  87.  
  88. packget    geta    message1r,a0
  89.     sub.l    a0,d0
  90.     divu    #(MN_SIZE+dp_SIZEOF),d0
  91.     swap    d0
  92.     tst.w    d0
  93.     bne.s    mainloop
  94.     swap    d0
  95.     cmp.w    #4,d0
  96.     bcc.s    mainloop
  97.     add.w    d0,d0
  98.     move.w    jumptab(pc,d0.w),d0
  99.     jmp    jumptab(pc,d0.w)
  100.  
  101. jumptab    dc.w    donerp1-jumptab,donerp2-jumptab
  102.     dc.w    donewp1-jumptab,donewp2-jumptab
  103.  
  104. ; Routines executed when various kinds of packets are done
  105.  
  106. donewp2    bclr    #3,d7
  107.     bclr    #0,d7
  108.     beq.s    mainloop
  109.     bra.s    resend1
  110.  
  111. donewp1    bclr    #2,d7
  112.     bclr    #1,d7
  113.     beq.s    mainloop
  114.     bra.s    resend2
  115.  
  116. donerp1    bset    #0,d7
  117.     btst    #3,d7
  118.     bne.s    mainloop
  119.     bclr    #0,d7
  120. resend1    geta    packet1r,a0
  121.     geta    packet2w,a1
  122.     get.l    file2,d0
  123.     geta    buf2w,a2
  124.     get.l    file1,d5
  125.     moveq    #3,d6
  126.     bra.s    resend
  127.  
  128. donerp2    bset    #1,d7
  129.     btst    #2,d7
  130.     bne    mainloop
  131.     bclr    #1,d7
  132. resend2    moveq    #2,d6
  133.     geta    packet2r,a0
  134.     geta    packet1w,a1
  135.     get.l    file1,d0
  136.     geta    buf1w,a2
  137.     get.l    file2,d5
  138.  
  139. resend    move.l    dp_Arg2(a0),a3    ; 'STOP' ?
  140.     cmp.l    #'STOP',(a3)+
  141.     bne.s    1$
  142.     cmp.b    #10,(a3)
  143.     beq.s    0$
  144. 1$    move.l    dp_Res1(a0),d4    ; EOF ?
  145.     beq.s    0$
  146.     bmi.s    0$        ; ERR ?
  147.  
  148.     bset    d6,d7
  149.     mpush    a0-a1
  150.     move.l    dp_Arg2(a0),a0    ; Copy the text
  151.     move.l    a2,a1
  152.     bra.s    11$
  153. 10$    move.b    (a0)+,(a1)+
  154. 11$    dbra    d4,10$
  155.  
  156.     move.l    (sp),a0        ; Resend read packet
  157.     push    dp_Res1(a0)
  158.     exg.l    d0,d5
  159.     bsr.s    sendpac1
  160.     mpop    d1/a0-a1
  161.     move.l    d5,d0
  162.     moveq    #ACTION_WRITE,d2
  163.     move.l    a1,a0
  164.     bsr.s    sendpacket
  165. 2$    bra    mainloop
  166.  
  167. 0$    addq.b    #4,d6        ; Stopped
  168.     bclr    d6,d7
  169.     bra.s    2$
  170.  
  171. ; Send packet read request
  172. ; A0=Packet,D0=FileHandle,A2=buffer
  173.  
  174. sendreadreq    moveq    #ACTION_READ,d2
  175.     move.l    #bufsize,d1
  176.  
  177. ; Send packet request
  178. ; A0=Packet,D0=FileHandle,A2=buffer,D1=Size,D2=Action#
  179.  
  180. sendpacket    move.l    a2,dp_Arg2(a0)
  181.     move.l    d1,dp_Arg3(a0)
  182.     move.l    d2,dp_Type(a0)
  183. sendpac1    move.l    d0,a1
  184.     add.l    a1,a1
  185.     add.l    a1,a1
  186.     move.l    fh_Arg1(a1),dp_Arg1(a0)
  187.     exg.l    a0,a1            ; A1=Packet,A0=FH
  188.     move.l    fh_Type(a0),a0        ; A0=Port
  189.     lea    -MN_SIZE(a1),a1
  190.     move.l    MN_REPLYPORT(a1),dp_Port+MN_SIZE(a1)
  191.     jump    exec,PutMsg
  192.  
  193. ; Everything done
  194.  
  195. mainend    jump    ss,ExitCleanup
  196.  
  197.     tags
  198.     finish
  199.     end
  200.