Subversion Repositories Kolibri OS

Rev

Rev 485 | 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  eax, 33
  469.  mov  ebx, source
  470.  mov  edx, [filesize]
  471.  mov  ecx, I_END + 512
  472.  mov  esi, 0
  473.  mcall
  474.    
  475.  jmp  cfrexit
  476.    
  477. cfrerr:
  478.  ; simple implementation on error - just read all data, and return
  479.  mov  eax, 53
  480.  mov  ebx, 3
  481.  mov  ecx, [socketNum]
  482.     int   0x40    ; read byte
  483.    
  484.  mov  eax, 53
  485.  mov  ebx, 2
  486.  mov  ecx, [socketNum]
  487.     int   0x40    ; any more data?
  488.    
  489.  cmp  eax, 0
  490.  jne  cfrerr    ; yes, so get it
  491.    
  492.  jmp  cfr006    ; close socket and close app
  493.    
  494. cfr003:                         ; redraw request
  495.     call draw_window
  496.     jmp  cfr002
  497.    
  498. cfr004:                         ; key pressed
  499.     mov  eax,2                  ; just read it and ignore
  500.     mcall
  501.     jmp  cfr002
  502.    
  503. cfr005:                        ; button
  504.     mov  eax,17                 ; get id
  505.     mcall
  506.    
  507.     cmp  ah,1                   ; button id=1 ?
  508.     jne  cfr002     ; If not, ignore.
  509.    
  510. cfr006:
  511.     ; close socket
  512.  mov  eax, 53
  513.  mov  ebx, 1
  514.  mov  ecx, [socketNum]
  515.     int   0x40
  516.    
  517.  mov  [socketNum], dword 0
  518.    
  519.     mov  eax,-1                 ; close this program
  520.     mcall
  521.    
  522.     jmp $
  523.    
  524. cfrexit:
  525.     ; close socket
  526.  mov  eax, 53
  527.  mov  ebx, 1
  528.  mov  ecx, [socketNum]
  529.     int   0x40
  530.    
  531.  mov  [socketNum], dword 0
  532.    
  533.     mov   dword [prompt], p4
  534.     mov  dword [promptlen], p4len - p4
  535.     call  draw_window            ;
  536.    
  537.  ret
  538.    
  539.    
  540.    
  541. ;***************************************************************************
  542. ;   Function
  543. ;      copyToRemote
  544. ;
  545. ;   Description
  546. ;
  547. ;***************************************************************************
  548. copyToRemote:
  549.     mov   eax,6    ; Read file from floppy (image)
  550.     mov   ebx,source
  551.     mov   ecx,0
  552.     mov   edx,0xffffffff
  553.     mov   esi,I_END + 512
  554.     int   0x40
  555.    
  556.     cmp   eax,0xffffffff
  557.     jnz   filefound
  558.    
  559.     mov   dword [prompt], p6
  560.     mov  dword [promptlen], p6len - p6
  561.     call  draw_window            ;
  562.  jmp  ctr_exit
  563.    
  564. filefound:
  565.  mov  [filesize], eax
  566.    
  567.  ; First, set up the file pointers
  568.  mov  eax, 0x01000300
  569.  mov  [blockBuffer], eax ; This makes sure our TFTP header is valid
  570.    
  571.  mov  eax, I_END + 512 ; This is the point where the file buffer is
  572.  mov  [fileposition], eax
  573.    
  574.  mov  eax, [filesize]
  575.  cmp  eax, 512
  576.  jb  ctr000
  577.  mov  eax, 512
  578. ctr000:
  579.  mov  [fileblocksize], ax
  580.    
  581.  ; Get a random # for the local socket port #
  582.  mov  eax, 3
  583.  int     0x40
  584.  mov  ecx, eax
  585.  shr  ecx, 8    ; Set up the local port # with a random #
  586.    
  587.    ; First, open socket
  588.  mov  eax, 53
  589.  mov  ebx, 0
  590.  mov  edx, 69    ; remote port
  591.  mov  esi, [tftp_IP]
  592.     int   0x40
  593.    
  594.    mov  [socketNum], eax
  595.    
  596.    ; write to socket ( request write file )
  597.  mov  eax, 53
  598.  mov  ebx, 4
  599.  mov  ecx, [socketNum]
  600.  mov  edx, [tftp_len]
  601.  mov  esi, tftp_filename
  602.     int   0x40
  603.    
  604.  ; now, we wait for
  605.  ; UI redraw
  606.  ; UI close
  607.  ; or data from remote
  608.    
  609. ctr001:
  610.     mov   eax,10                 ; wait here for event
  611.     int   0x40
  612.    
  613.     cmp   eax,1                  ; redraw request ?
  614.     je    ctr003
  615.     cmp   eax,2                  ; key in buffer ?
  616.     je    ctr004
  617.     cmp   eax,3                  ; button in buffer ?
  618.     je    ctr005
  619.    
  620.    
  621.     ; Any data in the UDP receive buffer?
  622.  mov  eax, 53
  623.  mov  ebx, 2
  624.  mov  ecx, [socketNum]
  625.     int   0x40
  626.    
  627.  cmp  eax, 0
  628.  je  ctr001
  629.    
  630.  ; Update the text on the display - once
  631.  mov  eax, [prompt]
  632.  cmp  eax, p2
  633.  je  ctr002
  634.    
  635.     mov   dword [prompt], p2
  636.     mov  dword [promptlen], p2len - p2
  637.     call  draw_window            ;
  638.    
  639.  ; we have data - this will be the ack
  640. ctr002:
  641.  mov  eax, 53
  642.  mov  ebx, 3
  643.  mov  ecx, [socketNum]
  644.     int   0x40   ; read byte - opcode
  645.    
  646.  mov  eax, 53
  647.  mov  ebx, 3
  648.  mov  ecx, [socketNum]
  649.     int   0x40   ; read byte - opcode
  650.    
  651.  mov  eax, 53
  652.  mov  ebx, 3
  653.  mov  ecx, [socketNum]
  654.     int   0x40   ; read byte - block (high byte)
  655.    
  656.  mov  [blockNumber], bl
  657.    
  658.  mov  eax, 53
  659.  mov  ebx, 3
  660.  mov  ecx, [socketNum]
  661.     int   0x40   ; read byte - block (low byte )
  662.    
  663.  mov  [blockNumber+1], bl
  664.    
  665. ctr0022:
  666.  mov  eax, 53
  667.  mov  ebx, 3
  668.  mov  ecx, [socketNum]
  669.     int   0x40   ; read byte (shouldn't have worked)
  670.    
  671.    
  672.  mov  eax, 53
  673.  mov  ebx, 2
  674.  mov  ecx, [socketNum]
  675.     int   0x40   ; any more data?
  676.    
  677.  cmp  eax, 0
  678.  jne  ctr0022  ; yes, so get it, and dump it
  679.    
  680.  ; If the ack is 0, it is to the request
  681.    
  682.  mov  bx, [blockNumber]
  683.  cmp  bx, 0
  684.  je   txd
  685.    
  686.  ; now, the ack should be one more than the current field - otherwise, resend
  687.    
  688.  cmp  bx, [blockBuffer+2]
  689.  jne  txre     ; not the same, so send again
  690.    
  691.  ; update the block number
  692.  mov  esi, blockBuffer + 3
  693.  mov  al, [esi]
  694.  inc  al
  695.  mov  [esi], al
  696.  cmp  al, 0
  697.  jne  ctr008
  698.  dec  esi
  699.  inc     byte [esi]
  700.    
  701. ctr008:
  702.  ; Move forward through the file
  703.  mov  eax, [fileposition]
  704.  movzx ebx, word [fileblocksize]
  705.  add  eax, ebx
  706.  mov  [fileposition], eax
  707.    
  708.  ; new ..
  709.  ; fs = 0 , fbs = 512 -> send with fbs = 0
  710.    
  711.  cmp  [filesize],0
  712.  jne  no_special_end
  713.  cmp  [fileblocksize],512
  714.  jne  no_special_end
  715.  mov  ax,0
  716.  jmp  ctr006
  717. no_special_end:
  718.    
  719.  mov  eax, [filesize]
  720.  cmp  eax, 0
  721.  je  ctr009
  722.  cmp  eax, 512
  723.  jb  ctr006
  724.  mov  eax, 512
  725. ctr006:
  726.  mov  [fileblocksize], ax
  727.    
  728.    
  729. txd:
  730.  ; Readjust the file size variable ( before sending )
  731.  mov  eax, [filesize]
  732.  movzx ebx, word [fileblocksize]
  733.  sub  eax, ebx
  734.  mov  [filesize], eax
  735.    
  736. txre:
  737.  ; Copy the fragment of the file to the block buffer
  738.  movzx ecx, word [fileblocksize]
  739.  mov  esi, [fileposition]
  740.  mov  edi, I_END
  741.  cld
  742.  rep  movsb
  743.    
  744.  ; send the file data
  745.  mov  eax, 53
  746.  mov  ebx, 4
  747.  mov  ecx, [socketNum]
  748.  movzx edx, word [fileblocksize]
  749.  add  edx, 4
  750.  mov  esi, blockBuffer
  751.     int   0x40
  752.    
  753.  jmp  ctr001
  754.    
  755. ctr003:                 ; redraw
  756.     call  draw_window
  757.     jmp   ctr001
  758.    
  759. ctr004:                 ; key
  760.     mov   eax,2          ; just read it and ignore
  761.     int   0x40
  762.     jmp   ctr001
  763.    
  764. ctr005:                 ; button
  765.     mov   eax,17         ; get id
  766.     int   0x40
  767.    
  768.     cmp   ah,1           ; button id=1 ?
  769.     jne   ctr001
  770.    
  771.     ; close socket
  772.  mov  eax, 53
  773.  mov  ebx, 1
  774.  mov  ecx, [socketNum]
  775.     int   0x40
  776.    
  777.  mov  [socketNum], dword 0
  778.    
  779.     mov   eax,-1         ; close this program
  780.     int   0x40
  781.  jmp  $
  782.    
  783. ctr009:
  784.     ; close socket
  785.  mov  eax, 53
  786.  mov  ebx, 1
  787.  mov  ecx, [socketNum]
  788.     int   0x40
  789.    
  790.     mov   dword [prompt], p4
  791.     mov  dword [promptlen], p4len - p4
  792.     call  draw_window            ;
  793.    
  794. ctr_exit:
  795.  ret
  796.    
  797.    
  798.    
  799.    
  800. ;   *********************************************
  801. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  802. ;   *********************************************
  803.    
  804.    
  805. draw_window:
  806.    
  807.     mov  eax,12                    ; function 12:tell os about windowdraw
  808.     mov  ebx,1                     ; 1, start of draw
  809.     mcall
  810.    
  811.                                    ; DRAW WINDOW
  812.     mov  eax,0                     ; function 0 : define and draw window
  813.     mov  ebx,100*65536+230         ; [x start] *65536 + [x size]
  814.     mov  ecx,100*65536+170         ; [y start] *65536 + [y size]
  815.     mov  edx,0x14224466            ; color of work area RRGGBB
  816.     mov  edi,title
  817.     mcall
  818.    
  819.     mov  eax,8              ; COPY BUTTON
  820.     mov  ebx,20*65536+190
  821.     mov  ecx,79*65536+15
  822.     mov  edx,2
  823.     mov  esi,0x557799
  824.     mcall
  825.    
  826.  ;   mov  eax,8             ; DELETE BUTTON
  827.     mov  ebx,20*65536+190
  828.     mov  ecx,111*65536+15
  829.     mov  edx,3
  830.     mcall
  831.    
  832.  ;   mov  eax,8
  833.  ;   mov  ebx,200*65536+10
  834.     mov  ecx,34*65536+10
  835.     mov  edx,4
  836.     mcall
  837.    
  838.  ;   mov  eax,8
  839.  ;   mov  ebx,200*65536+10
  840.     mov  ecx,50*65536+10
  841.     mov  edx,5
  842.     mcall
  843.    
  844.    
  845.  ; Copy the file name to the screen buffer
  846.  ; file name is same length as IP address, to
  847.  ; make the math easier later.
  848.     cld
  849.     mov  esi,source
  850.     mov  edi,text+13
  851.     mov  ecx,15
  852.     rep  movsb
  853.    
  854.    
  855.  ; copy the IP address to the screen buffer
  856.     mov  esi,destination
  857.     mov  edi,text+40+13
  858.     mov  ecx,15
  859.     rep  movsb
  860.    
  861.   ; copy the prompt to the screen buffer
  862.     mov  esi,[prompt]
  863.     mov  edi,text+280
  864.     mov  ecx,[promptlen]
  865.     rep  movsb
  866.    
  867.     ; Re-draw the screen text
  868.     cld
  869.     mov  eax,4
  870.     mov  ebx,25*65536+35           ; draw info text with function 4
  871.     mov  ecx,0xffffff
  872.     mov  edx,text
  873.     mov  esi,40
  874.   newline:
  875.     mcall
  876.     add  ebx,16
  877.     add  edx,40
  878.     cmp  [edx],byte 'x'
  879.     jnz  newline
  880.    
  881.    
  882.     mov  eax,12                    ; function 12:tell os about windowdraw
  883.     mov  ebx,2                     ; 2, end of draw
  884.     mcall
  885.    
  886.     ret
  887.    
  888.    
  889. ; DATA AREA
  890.    
  891. source       db  'KERNEL.ASM     '
  892. destination  db  '192.168.1.23   '
  893.    
  894.    
  895. tftp_filename:  times 15 + 9 db 0
  896. tftp_IP:   dd 0
  897. tftp_len:   dd 0
  898.    
  899. addr  dd  0x0
  900. ya    dd  0x0
  901.    
  902. fileposition dd 0 ; Points to the current point in the file
  903. filesize  dd 0 ; The number of bytes written / left to write
  904. fileblocksize dw 0 ; The number of bytes to send in this frame
  905.    
  906. text:
  907.     db 'SOURCE FILE: xxxxxxxxxxxxxxx            '
  908.     db 'HOST IP ADD: xxx.xxx.xxx.xxx            '
  909.     db '                                        '
  910.     db '  COPY HOST   ->   LOCAL                '
  911.     db '                                        '
  912.     db '  COPY LOCAL  ->   HOST                 '
  913.     db '                                        '
  914.     db '                                        '
  915.     db 'x' ; <- END MARKER, DONT DELETE
  916.    
  917.    
  918. title   db   'TFTP Client',0  
  919.    
  920. prompt: dd 0
  921. promptlen: dd 0
  922.    
  923.    
  924. p1:  db 'Waiting for Command'
  925. p1len:
  926.    
  927. p2:  db 'Sending File       '
  928. p2len:
  929.    
  930. p3:  db 'Receiving File     '
  931. p3len:
  932.    
  933. p4:  db 'Tranfer Complete   '
  934. p4len:
  935.    
  936. p5:  db 'Contacting Host... '
  937. p5len:
  938.    
  939. p6:  db 'File not found.    '
  940. p6len:
  941.    
  942. ack:
  943.  db 00,04,0,1
  944. ackLen:
  945.    
  946. socketNum:
  947.  dd 0
  948.    
  949. blockNumber:
  950.  dw 0
  951.    
  952. ; This must be the last part of the file, because the blockBuffer
  953. ; continues at I_END.
  954. blockBuffer:
  955.  db 00, 03, 00, 01
  956. I_END:
  957.    
  958.    
  959.    
  960.    
  961.    
  962.    
  963.