Subversion Repositories Kolibri OS

Rev

Rev 551 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;    TFTP Client
  3.    
  4. use32
  5.  org    0x0
  6.  db     'MENUET01'    ; header
  7.  dd     0x01          ; header version
  8.  dd     START         ; entry point
  9.  dd     I_END         ; image size
  10.  dd     I_END+0x10000 ; required memory
  11.  dd     I_END+0x10000 ; esp
  12.  dd     0x0 , 0x0     ; I_Param , I_Path
  13.  
  14. include 'lang.inc'
  15. include '..\..\..\macros.inc'
  16.    
  17. START:                          ; start of execution
  18.      mov  eax,40                 ; Report events
  19.      mov  ebx,10000111b          ; Stack 8 + defaults
  20.      mcall
  21.    
  22.     mov   dword [prompt], p1
  23.     mov  dword [promptlen], p1len - p1
  24.  
  25. red:  
  26.     call draw_window            ; at first, draw the window
  27.    
  28. still:
  29.     mov  eax,10                 ; wait here for event
  30.     mcall
  31.    
  32.     cmp  eax,1                  ; redraw request ?
  33.     jz   red
  34.     cmp  eax,2                  ; key in buffer ?
  35.     jz   key
  36.     cmp  eax,3                  ; button in buffer ?
  37.     jz   button
  38.    
  39.     jmp  still
  40.  
  41. key:                           ; Keys are not valid at this part of the
  42.     mov  eax,2                  ; loop. Just read it and ignore
  43.     mcall
  44.     jmp  still
  45.    
  46. button:                        ; button
  47.     mov  eax,17                 ; get id
  48.     mcall
  49.    
  50.     cmp  ah,1                   ; button id=1 ?
  51.     jnz  noclose
  52.    
  53.    
  54.     ; close socket before exiting
  55.  mov  eax, 53
  56.  mov  ebx, 1
  57.  mov  ecx, [socketNum]
  58.     int   0x40
  59.    
  60.  mov  [socketNum], dword 0
  61.    
  62.    
  63.     or  eax,-1  ; close this program
  64.     mcall
  65.    
  66. noclose:
  67.     cmp  ah,2                   ; copy file to local machine?
  68.     jnz  nocopyl
  69.    
  70.     mov   dword [prompt], p5
  71.     mov  dword [promptlen], p5len - p5
  72.     call  draw_window            ;
  73.    
  74.     ; Copy File from Remote Host to this machine
  75.     call translateData  ; Convert Filename & IP address
  76.     mov  edi, tftp_filename + 1
  77.     mov  [edi], byte 0x01 ; setup tftp msg
  78.     call copyFromRemote
  79.    
  80.     jmp  still
  81.    
  82. nocopyl:
  83.    
  84.     cmp  ah,3        ; Copy file to host?
  85.     jnz  nocopyh
  86.    
  87.     mov   dword [prompt], p5
  88.     mov  dword [promptlen], p5len - p5
  89.     call  draw_window            ;
  90.    
  91.     ; Copy File from this machine to Remote Host
  92.     call translateData  ; Convert Filename & IP address
  93.     mov  edi, tftp_filename + 1
  94.     mov  [edi], byte 0x02 ; setup tftp msg
  95.     call copyToRemote
  96.    
  97.     jmp  still
  98.    
  99. nocopyh:
  100.     cmp  ah,4
  101.     jz   f1
  102.     cmp  ah,5
  103.     jz   f2
  104.     jmp  nof12
  105.    
  106.   f1:
  107.     mov  [addr],dword source
  108.     mov  [ya],dword 35
  109.     jmp  rk
  110.    
  111.   f2:
  112.     mov  [addr],dword destination
  113.     mov  [ya],dword 35+16
  114.    
  115.   rk:
  116.     mov  ecx,15
  117.     mov  edi,[addr]
  118.     mov  al,' '
  119.     rep  stosb
  120.    
  121.     call print_text
  122.    
  123.     mov  edi,[addr]
  124.    
  125.   f11:
  126.     mov  eax,10
  127.     mcall
  128.     cmp  eax,2
  129.     jz   fbu
  130.     jmp  still
  131.   fbu:
  132.     mov  eax,2
  133.     mcall  ; get key
  134.     shr  eax,8
  135.     cmp  eax,8
  136.     jnz  nobs
  137.     cmp  edi,[addr]
  138.     jz   f11
  139.     sub  edi,1
  140.     mov  [edi],byte ' '
  141.     call print_text
  142.     jmp  f11
  143.   nobs:
  144.     cmp  eax,dword 31
  145.     jbe  f11
  146.     cmp  eax,dword 95
  147.     jb   keyok
  148.     sub  eax,32
  149.   keyok:
  150.     mov  [edi],al
  151.    
  152.     call print_text
  153.    
  154.     add  edi,1
  155.     mov  esi,[addr]
  156.     add  esi,15
  157.     cmp  esi,edi
  158.     jnz  f11
  159.    
  160.     jmp  still
  161.    
  162. print_text:
  163.    
  164.     mov  eax,13
  165.     mov  ebx,103*65536+15*6
  166.     mov  ecx,[ya]
  167.     shl  ecx,16
  168.     mov  cx,8
  169.     mov  edx,0x224466
  170.     mcall
  171.    
  172.     mov  eax,4
  173.     mov  ebx,103*65536
  174.     add  ebx,[ya]
  175.     mov  ecx,0xffffff
  176.     mov  edx,[addr]
  177.     mov  esi,15
  178.     mcall
  179.    
  180.     ret
  181.    
  182.    
  183.   nof12:
  184.     jmp  still
  185.    
  186.    
  187. ;***************************************************************************
  188. ;   Function
  189. ;      translateData
  190. ;
  191. ;   Description
  192. ;      Coverts the filename and IP address typed in by the user into
  193. ;      a format suitable for the IP layer.
  194. ;
  195. ;    The filename, in source, is converted and stored in tftp_filename
  196. ;      The host ip, in destination, is converted and stored in tftp_IP
  197. ;
  198. ;***************************************************************************
  199. translateData:
  200.    
  201.  ; first, build up the tftp command string. This includes the filename
  202.  ; and the transfer protocol
  203.    
  204.    
  205.  ; First, write 0,0
  206.  mov  al, 0
  207.  mov  edi, tftp_filename
  208.  mov  [edi], al
  209.  inc  edi
  210.  mov  [edi], al
  211.  inc  edi
  212.    
  213.  ; Now, write the file name itself, and null terminate it
  214.  mov  ecx, 15
  215.  mov  ah, ' '
  216.  mov  esi, source
  217.    
  218. td001:
  219.  lodsb
  220.  stosb
  221.  cmp  al, ah
  222.  loopnz td001
  223.    
  224.  cmp  al,ah  ; Was the entire buffer full of characters?
  225.  jne  td002
  226.  dec  edi   ; No - so remove ' ' character
  227.    
  228. td002:
  229.  mov  [edi], byte 0
  230.  inc  edi
  231.  mov  [edi], byte 'O'
  232.  inc  edi
  233.  mov  [edi], byte 'C'
  234.  inc  edi
  235.  mov  [edi], byte 'T'
  236.  inc  edi
  237.  mov  [edi], byte 'E'
  238.  inc  edi
  239.  mov  [edi], byte 'T'
  240.  inc  edi
  241.  mov  [edi], byte 0
  242.    
  243.  mov  esi, tftp_filename
  244.  sub  edi, esi
  245.  mov  [tftp_len], edi
  246.    
  247.    
  248.  ; Now, convert the typed IP address into a real address
  249.  ; No validation is done on the number entered
  250.  ; ip addresses must be typed in normally, eg
  251.  ; 192.1.45.24
  252.    
  253.  xor  eax, eax
  254.  mov  dh, 10
  255.  mov  dl, al
  256.  mov  [tftp_IP], eax
  257.    
  258.  ; 192.168.24.1   1.1.1.1       1. 9.2.3.
  259.    
  260.  mov  esi, destination
  261.  mov  edi, tftp_IP
  262.    
  263.  mov  ecx, 4
  264.    
  265. td003:
  266.  lodsb
  267.  sub  al, '0'
  268.  add  dl, al
  269.  lodsb
  270.  cmp  al, '.'
  271.  je  ipNext
  272.  cmp  al, ' '
  273.  je  ipNext
  274.  mov  dh, al
  275.  sub  dh, '0'
  276.  mov  al, 10
  277.  mul  dl
  278.  add  al, dh
  279.  mov  dl, al
  280.  lodsb
  281.  cmp  al, '.'
  282.  je  ipNext
  283.  cmp  al, ' '
  284.  je  ipNext
  285.  mov  dh, al
  286.  sub  dh, '0'
  287.  mov  al, 10
  288.  mul  dl
  289.  add  al, dh
  290.  mov  dl, al
  291.  lodsb
  292.    
  293. ipNext:
  294.  mov  [edi], dl
  295.  inc  edi
  296.  mov  dl, 0
  297.  loop td003
  298.    
  299.  ret
  300.    
  301.    
  302.    
  303. ;***************************************************************************
  304. ;   Function
  305. ;      copyFromRemote
  306. ;
  307. ;   Description
  308. ;
  309. ;***************************************************************************
  310. copyFromRemote:
  311.  xor  eax, eax
  312.  mov  [filesize], eax
  313.  mov  eax, I_END + 512 ; This is the point where the file buffer is
  314.  mov  [fileposition], eax
  315.    
  316.  ; Get a random # for the local socket port #
  317.  mov  eax, 3
  318.  int     0x40
  319.  mov  ecx, eax
  320.  shr  ecx, 8    ; Set up the local port # with a random #
  321.    
  322.    ; open socket
  323.  mov  eax, 53
  324.  mov  ebx, 0
  325.  mov  edx, 69    ; remote port
  326.  mov  esi, [tftp_IP]  ; remote IP ( in intenet format )
  327.     int   0x40
  328.    
  329.    mov  [socketNum], eax
  330.    
  331.  ; make sure there is no data in the socket - there shouldn't be..
  332.    
  333. cfr001:
  334.  mov  eax, 53
  335.  mov  ebx, 3
  336.  mov  ecx, [socketNum]
  337.     int   0x40    ; read byte
  338.    
  339.  mov  eax, 53
  340.  mov  ebx, 2
  341.  mov  ecx, [socketNum]
  342.     int   0x40    ; any more data?
  343.    
  344.  cmp  eax, 0
  345.  jne  cfr001    ; yes, so get it
  346.    
  347.  ; Now, request the file
  348.  mov  eax, 53
  349.  mov  ebx, 4
  350.  mov  ecx, [socketNum]
  351.  mov  edx, [tftp_len]
  352.  mov  esi, tftp_filename
  353.     int   0x40
  354.    
  355. cfr002:
  356.     mov  eax,10                 ; wait here for event
  357.     mcall
  358.    
  359.     cmp  eax,1                  ; redraw request ?
  360.     je   cfr003
  361.     cmp  eax,2                  ; key in buffer ?
  362.     je   cfr004
  363.     cmp  eax,3                  ; button in buffer ?
  364.     je   cfr005
  365.    
  366.     ; Any data to fetch?
  367.  mov  eax, 53
  368.  mov  ebx, 2
  369.  mov  ecx, [socketNum]
  370.     int   0x40
  371.    
  372.  cmp  eax, 0
  373.  je  cfr002
  374.    
  375.  push eax     ; eax holds # chars
  376.    
  377.  ; Update the text on the display - once
  378.  mov  eax, [prompt]
  379.  cmp  eax, p3
  380.  je  cfr008
  381.     mov   dword [prompt], p3
  382.     mov  dword [promptlen], p3len - p3
  383.     call  draw_window            ;
  384.    
  385. cfr008:
  386.  ; we have data - this will be a tftp frame
  387.    
  388.  ; read first two bytes - opcode
  389.  mov  eax, 53
  390.  mov  ebx, 3
  391.  mov  ecx, [socketNum]
  392.     int   0x40   ; read byte
  393.    
  394.  mov  eax, 53
  395.  mov  ebx, 3
  396.  mov  ecx, [socketNum]
  397.     int   0x40   ; read byte
  398.    
  399.  pop  eax
  400.  ; bl holds tftp opcode. Can only be 3 (data) or 5 ( error )
  401.    
  402.  cmp  bl, 3
  403.  jne  cfrerr
  404.    
  405.  push eax
  406.    
  407.  ; do data stuff. Read block #. Read data. Send Ack.
  408.  mov  eax, 53
  409.  mov  ebx, 3
  410.  mov  ecx, [socketNum]
  411.     int   0x40   ; read byte
  412.    
  413.  mov  [blockNumber], bl
  414.    
  415.  mov  eax, 53
  416.  mov  ebx, 3
  417.  mov  ecx, [socketNum]
  418.  int   0x40   ; read byte
  419.    
  420.  mov  [blockNumber+1], bl
  421.    
  422. cfr007:
  423.    
  424.  mov  eax, 53
  425.  mov  ebx, 2
  426.  mov  ecx, [socketNum]
  427.  mcall   ; any more data?
  428.    
  429.  cmp  eax, 0
  430.  je   no_more_data ; no
  431.    
  432.  mov  eax, 53
  433.  mov  ebx, 3
  434.  mov  ecx, [socketNum]
  435.  mcall   ; read byte
  436.    
  437.  mov  esi, [fileposition]
  438.  mov  [esi], bl
  439.  inc  dword [fileposition]
  440.  inc  dword [filesize]
  441.    
  442.  jmp  cfr007                                           
  443.    
  444. no_more_data:
  445.    
  446.  ; write the block number into the ack
  447.  mov  al, [blockNumber]
  448.  mov  [ack + 2], al
  449.    
  450.  mov  al, [blockNumber+1]
  451.  mov  [ack + 3], al
  452.    
  453.  ; send an 'ack'
  454.  mov  eax, 53
  455.  mov  ebx, 4
  456.  mov  ecx, [socketNum]
  457.  mov  edx, ackLen - ack
  458.  mov  esi, ack
  459.     int   0x40
  460.    
  461.  ; If # of chars in the frame is less that 516,
  462.  ; this frame is the last
  463.  pop  eax
  464.  cmp  eax, 516
  465.  je  cfr002
  466.    
  467.  ; Write the file
  468.         mov     ebx, writeinfo
  469.         lea     esi, [ebx + 20]
  470. @@:
  471.         lodsb
  472.         test    al, al
  473.         jnz     @b
  474. @@:
  475.         dec     esi
  476.         cmp     byte [esi-1], ' '
  477.         jnz     @b
  478.         mov     byte [esi], 0
  479.         mcall   70, writeinfo
  480.         mov     byte [esi], ' '
  481.    
  482.  jmp  cfrexit
  483.    
  484. cfrerr:
  485.  ; simple implementation on error - just read all data, and return
  486.  mov  eax, 53
  487.  mov  ebx, 3
  488.  mov  ecx, [socketNum]
  489.     int   0x40    ; read byte
  490.    
  491.  mov  eax, 53
  492.  mov  ebx, 2
  493.  mov  ecx, [socketNum]
  494.     int   0x40    ; any more data?
  495.    
  496.  cmp  eax, 0
  497.  jne  cfrerr    ; yes, so get it
  498.    
  499.  jmp  cfr006    ; close socket and close app
  500.    
  501. cfr003:                         ; redraw request
  502.     call draw_window
  503.     jmp  cfr002
  504.    
  505. cfr004:                         ; key pressed
  506.     mov  eax,2                  ; just read it and ignore
  507.     mcall
  508.     jmp  cfr002
  509.    
  510. cfr005:                        ; button
  511.     mov  eax,17                 ; get id
  512.     mcall
  513.    
  514.     cmp  ah,1                   ; button id=1 ?
  515.     jne  cfr002     ; If not, ignore.
  516.    
  517. cfr006:
  518.     ; close socket
  519.  mov  eax, 53
  520.  mov  ebx, 1
  521.  mov  ecx, [socketNum]
  522.     int   0x40
  523.    
  524.  mov  [socketNum], dword 0
  525.    
  526.     mov  eax,-1                 ; close this program
  527.     mcall
  528.    
  529.     jmp $
  530.    
  531. cfrexit:
  532.     ; close socket
  533.  mov  eax, 53
  534.  mov  ebx, 1
  535.  mov  ecx, [socketNum]
  536.     int   0x40
  537.    
  538.  mov  [socketNum], dword 0
  539.    
  540.     mov   dword [prompt], p4
  541.     mov  dword [promptlen], p4len - p4
  542.     call  draw_window            ;
  543.    
  544.  ret
  545.    
  546.    
  547.    
  548. ;***************************************************************************
  549. ;   Function
  550. ;      copyToRemote
  551. ;
  552. ;   Description
  553. ;
  554. ;***************************************************************************
  555. copyToRemote:
  556.     mov   eax,6    ; Read file from floppy (image)
  557.     mov   ebx,source
  558.     mov   ecx,0
  559.     mov   edx,0xffffffff
  560.     mov   esi,I_END + 512
  561.     int   0x40
  562.    
  563.     cmp   eax,0xffffffff
  564.     jnz   filefound
  565.    
  566.     mov   dword [prompt], p6
  567.     mov  dword [promptlen], p6len - p6
  568.     call  draw_window            ;
  569.  jmp  ctr_exit
  570.    
  571. filefound:
  572.  mov  [filesize], eax
  573.    
  574.  ; First, set up the file pointers
  575.  mov  eax, 0x01000300
  576.  mov  [blockBuffer], eax ; This makes sure our TFTP header is valid
  577.    
  578.  mov  eax, I_END + 512 ; This is the point where the file buffer is
  579.  mov  [fileposition], eax
  580.    
  581.  mov  eax, [filesize]
  582.  cmp  eax, 512
  583.  jb  ctr000
  584.  mov  eax, 512
  585. ctr000:
  586.  mov  [fileblocksize], ax
  587.    
  588.  ; Get a random # for the local socket port #
  589.  mov  eax, 3
  590.  int     0x40
  591.  mov  ecx, eax
  592.  shr  ecx, 8    ; Set up the local port # with a random #
  593.    
  594.    ; First, open socket
  595.  mov  eax, 53
  596.  mov  ebx, 0
  597.  mov  edx, 69    ; remote port
  598.  mov  esi, [tftp_IP]
  599.     int   0x40
  600.    
  601.    mov  [socketNum], eax
  602.    
  603.    ; write to socket ( request write file )
  604.  mov  eax, 53
  605.  mov  ebx, 4
  606.  mov  ecx, [socketNum]
  607.  mov  edx, [tftp_len]
  608.  mov  esi, tftp_filename
  609.     int   0x40
  610.    
  611.  ; now, we wait for
  612.  ; UI redraw
  613.  ; UI close
  614.  ; or data from remote
  615.    
  616. ctr001:
  617.     mov   eax,10                 ; wait here for event
  618.     int   0x40
  619.    
  620.     cmp   eax,1                  ; redraw request ?
  621.     je    ctr003
  622.     cmp   eax,2                  ; key in buffer ?
  623.     je    ctr004
  624.     cmp   eax,3                  ; button in buffer ?
  625.     je    ctr005
  626.    
  627.    
  628.     ; Any data in the UDP receive buffer?
  629.  mov  eax, 53
  630.  mov  ebx, 2
  631.  mov  ecx, [socketNum]
  632.     int   0x40
  633.    
  634.  cmp  eax, 0
  635.  je  ctr001
  636.    
  637.  ; Update the text on the display - once
  638.  mov  eax, [prompt]
  639.  cmp  eax, p2
  640.  je  ctr002
  641.    
  642.     mov   dword [prompt], p2
  643.     mov  dword [promptlen], p2len - p2
  644.     call  draw_window            ;
  645.    
  646.  ; we have data - this will be the ack
  647. ctr002:
  648.  mov  eax, 53
  649.  mov  ebx, 3
  650.  mov  ecx, [socketNum]
  651.     int   0x40   ; read byte - opcode
  652.    
  653.  mov  eax, 53
  654.  mov  ebx, 3
  655.  mov  ecx, [socketNum]
  656.     int   0x40   ; read byte - opcode
  657.    
  658.  mov  eax, 53
  659.  mov  ebx, 3
  660.  mov  ecx, [socketNum]
  661.     int   0x40   ; read byte - block (high byte)
  662.    
  663.  mov  [blockNumber], bl
  664.    
  665.  mov  eax, 53
  666.  mov  ebx, 3
  667.  mov  ecx, [socketNum]
  668.     int   0x40   ; read byte - block (low byte )
  669.    
  670.  mov  [blockNumber+1], bl
  671.    
  672. ctr0022:
  673.  mov  eax, 53
  674.  mov  ebx, 3
  675.  mov  ecx, [socketNum]
  676.     int   0x40   ; read byte (shouldn't have worked)
  677.    
  678.    
  679.  mov  eax, 53
  680.  mov  ebx, 2
  681.  mov  ecx, [socketNum]
  682.     int   0x40   ; any more data?
  683.    
  684.  cmp  eax, 0
  685.  jne  ctr0022  ; yes, so get it, and dump it
  686.    
  687.  ; If the ack is 0, it is to the request
  688.    
  689.  mov  bx, [blockNumber]
  690.  cmp  bx, 0
  691.  je   txd
  692.    
  693.  ; now, the ack should be one more than the current field - otherwise, resend
  694.    
  695.  cmp  bx, [blockBuffer+2]
  696.  jne  txre     ; not the same, so send again
  697.    
  698.  ; update the block number
  699.  mov  esi, blockBuffer + 3
  700.  mov  al, [esi]
  701.  inc  al
  702.  mov  [esi], al
  703.  cmp  al, 0
  704.  jne  ctr008
  705.  dec  esi
  706.  inc     byte [esi]
  707.    
  708. ctr008:
  709.  ; Move forward through the file
  710.  mov  eax, [fileposition]
  711.  movzx ebx, word [fileblocksize]
  712.  add  eax, ebx
  713.  mov  [fileposition], eax
  714.    
  715.  ; new ..
  716.  ; fs = 0 , fbs = 512 -> send with fbs = 0
  717.    
  718.  cmp  [filesize],0
  719.  jne  no_special_end
  720.  cmp  [fileblocksize],512
  721.  jne  no_special_end
  722.  mov  ax,0
  723.  jmp  ctr006
  724. no_special_end:
  725.    
  726.  mov  eax, [filesize]
  727.  cmp  eax, 0
  728.  je  ctr009
  729.  cmp  eax, 512
  730.  jb  ctr006
  731.  mov  eax, 512
  732. ctr006:
  733.  mov  [fileblocksize], ax
  734.    
  735.    
  736. txd:
  737.  ; Readjust the file size variable ( before sending )
  738.  mov  eax, [filesize]
  739.  movzx ebx, word [fileblocksize]
  740.  sub  eax, ebx
  741.  mov  [filesize], eax
  742.    
  743. txre:
  744.  ; Copy the fragment of the file to the block buffer
  745.  movzx ecx, word [fileblocksize]
  746.  mov  esi, [fileposition]
  747.  mov  edi, I_END
  748.  cld
  749.  rep  movsb
  750.    
  751.  ; send the file data
  752.  mov  eax, 53
  753.  mov  ebx, 4
  754.  mov  ecx, [socketNum]
  755.  movzx edx, word [fileblocksize]
  756.  add  edx, 4
  757.  mov  esi, blockBuffer
  758.     int   0x40
  759.    
  760.  jmp  ctr001
  761.    
  762. ctr003:                 ; redraw
  763.     call  draw_window
  764.     jmp   ctr001
  765.    
  766. ctr004:                 ; key
  767.     mov   eax,2          ; just read it and ignore
  768.     int   0x40
  769.     jmp   ctr001
  770.    
  771. ctr005:                 ; button
  772.     mov   eax,17         ; get id
  773.     int   0x40
  774.    
  775.     cmp   ah,1           ; button id=1 ?
  776.     jne   ctr001
  777.    
  778.     ; close socket
  779.  mov  eax, 53
  780.  mov  ebx, 1
  781.  mov  ecx, [socketNum]
  782.     int   0x40
  783.    
  784.  mov  [socketNum], dword 0
  785.    
  786.     mov   eax,-1         ; close this program
  787.     int   0x40
  788.  jmp  $
  789.    
  790. ctr009:
  791.     ; close socket
  792.  mov  eax, 53
  793.  mov  ebx, 1
  794.  mov  ecx, [socketNum]
  795.     int   0x40
  796.    
  797.     mov   dword [prompt], p4
  798.     mov  dword [promptlen], p4len - p4
  799.     call  draw_window            ;
  800.    
  801. ctr_exit:
  802.  ret
  803.    
  804.    
  805.    
  806.    
  807. ;   *********************************************
  808. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  809. ;   *********************************************
  810.    
  811.    
  812. draw_window:
  813.    
  814.     mov  eax,12                    ; function 12:tell os about windowdraw
  815.     mov  ebx,1                     ; 1, start of draw
  816.     mcall
  817.    
  818.                                    ; DRAW WINDOW
  819.     mov  eax,0                     ; function 0 : define and draw window
  820.     mov  ebx,100*65536+230         ; [x start] *65536 + [x size]
  821.     mov  ecx,100*65536+170         ; [y start] *65536 + [y size]
  822.     mov  edx,0x14224466            ; color of work area RRGGBB
  823.     mov  edi,title
  824.     mcall
  825.    
  826.     mov  eax,8              ; COPY BUTTON
  827.     mov  ebx,20*65536+190
  828.     mov  ecx,79*65536+15
  829.     mov  edx,2
  830.     mov  esi,0x557799
  831.     mcall
  832.    
  833.  ;   mov  eax,8             ; DELETE BUTTON
  834.     mov  ebx,20*65536+190
  835.     mov  ecx,111*65536+15
  836.     mov  edx,3
  837.     mcall
  838.    
  839.  ;   mov  eax,8
  840.  ;   mov  ebx,200*65536+10
  841.     mov  ecx,34*65536+10
  842.     mov  edx,4
  843.     mcall
  844.    
  845.  ;   mov  eax,8
  846.  ;   mov  ebx,200*65536+10
  847.     mov  ecx,50*65536+10
  848.     mov  edx,5
  849.     mcall
  850.    
  851.    
  852.  ; Copy the file name to the screen buffer
  853.  ; file name is same length as IP address, to
  854.  ; make the math easier later.
  855.     cld
  856.     mov  esi,source
  857.     mov  edi,text+13
  858.     mov  ecx,15
  859.     rep  movsb
  860.    
  861.    
  862.  ; copy the IP address to the screen buffer
  863.     mov  esi,destination
  864.     mov  edi,text+40+13
  865.     mov  ecx,15
  866.     rep  movsb
  867.    
  868.   ; copy the prompt to the screen buffer
  869.     mov  esi,[prompt]
  870.     mov  edi,text+280
  871.     mov  ecx,[promptlen]
  872.     rep  movsb
  873.    
  874.     ; Re-draw the screen text
  875.     cld
  876.     mov  eax,4
  877.     mov  ebx,25*65536+35           ; draw info text with function 4
  878.     mov  ecx,0xffffff
  879.     mov  edx,text
  880.     mov  esi,40
  881.   newline:
  882.     mcall
  883.     add  ebx,16
  884.     add  edx,40
  885.     cmp  [edx],byte 'x'
  886.     jnz  newline
  887.    
  888.    
  889.     mov  eax,12                    ; function 12:tell os about windowdraw
  890.     mov  ebx,2                     ; 2, end of draw
  891.     mcall
  892.    
  893.     ret
  894.    
  895.    
  896. ; DATA AREA
  897. ; file name: source
  898. ; file data: I_END + 512
  899. ; file size: [filesize]
  900. writeinfo:
  901.         dd      2
  902.         dd      0
  903.         dd      0
  904. filesize dd     0        ; The number of bytes written / left to write
  905.         dd      I_END + 512
  906. source       db  'KERNEL.ASM     ',0
  907. destination  db  '192.168.1.23   '
  908.    
  909.    
  910. tftp_filename:  times 15 + 9 db 0
  911. tftp_IP:   dd 0
  912. tftp_len:   dd 0
  913.    
  914. addr  dd  0x0
  915. ya    dd  0x0
  916.    
  917. fileposition dd 0 ; Points to the current point in the file
  918. fileblocksize dw 0 ; The number of bytes to send in this frame
  919.    
  920. text:
  921.     db 'SOURCE FILE: xxxxxxxxxxxxxxx            '
  922.     db 'HOST IP ADD: xxx.xxx.xxx.xxx            '
  923.     db '                                        '
  924.     db '  COPY HOST   ->   LOCAL                '
  925.     db '                                        '
  926.     db '  COPY LOCAL  ->   HOST                 '
  927.     db '                                        '
  928.     db '                                        '
  929.     db 'x' ; <- END MARKER, DONT DELETE
  930.    
  931.    
  932. title   db   'TFTP Client',0  
  933.    
  934. prompt: dd 0
  935. promptlen: dd 0
  936.    
  937.    
  938. p1:  db 'Waiting for Command'
  939. p1len:
  940.    
  941. p2:  db 'Sending File       '
  942. p2len:
  943.    
  944. p3:  db 'Receiving File     '
  945. p3len:
  946.    
  947. p4:  db 'Tranfer Complete   '
  948. p4len:
  949.    
  950. p5:  db 'Contacting Host... '
  951. p5len:
  952.    
  953. p6:  db 'File not found.    '
  954. p6len:
  955.    
  956. ack:
  957.  db 00,04,0,1
  958. ackLen:
  959.    
  960. socketNum:
  961.  dd 0
  962.    
  963. blockNumber:
  964.  dw 0
  965.    
  966. ; This must be the last part of the file, because the blockBuffer
  967. ; continues at I_END.
  968. blockBuffer:
  969.  db 00, 03, 00, 01
  970. I_END:
  971.    
  972.    
  973.    
  974.    
  975.    
  976.    
  977.