Subversion Repositories Kolibri OS

Rev

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