Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;    TFTP Client
3
;
4
;    Compile with FASM for Menuet
5
;
6
 
7
use32
8
 
9
                org     0x0
10
 
11
                db      'MENUET00'              ; 8 byte id
12
                dd      38                      ; required os
13
                dd      START                   ; program start
14
                dd      I_END                   ; program image size
15
                dd      0x100000                ; required amount of memory
16
                dd      0x00000000              ; reserved=no extended header
17
 
18
include 'lang.inc'
19
include 'macros.inc'
20
 
21
START:                          ; start of execution
22
     mov  eax,40                 ; Report events
23
     mov  ebx,10000111b          ; Stack 8 + defaults
24
     int  0x40
25
 
26
    mov   dword [prompt], p1
27
    mov  dword [promptlen], p1len - p1
28
 
29
    call draw_window            ; at first, draw the window
30
 
31
still:
32
    mov  eax,10                 ; wait here for event
33
    int  0x40
34
 
35
    cmp  eax,1                  ; redraw request ?
36
    jz   red
37
    cmp  eax,2                  ; key in buffer ?
38
    jz   key
39
    cmp  eax,3                  ; button in buffer ?
40
    jz   button
41
 
42
    jmp  still
43
 
44
red:                           ; redraw
45
    call draw_window
46
    jmp  still
47
 
48
key:                           ; Keys are not valid at this part of the
49
    mov  eax,2                  ; loop. Just read it and ignore
50
    int  0x40
51
    jmp  still
52
 
53
button:                        ; button
54
    mov  eax,17                 ; get id
55
    int  0x40
56
 
57
    cmp  ah,1                   ; button id=1 ?
58
    jnz  noclose
59
 
60
 
61
    ; close socket before exiting
62
 mov  eax, 53
63
 mov  ebx, 1
64
 mov  ecx, [socketNum]
65
    int   0x40
66
 
67
 mov  [socketNum], dword 0
68
 
69
 
70
    mov  eax,0xffffffff         ; close this program
71
    int  0x40
72
 
73
noclose:
74
    cmp  ah,2                   ; copy file to local machine?
75
    jnz  nocopyl
76
 
77
    mov   dword [prompt], p5
78
    mov  dword [promptlen], p5len - p5
79
    call  draw_window            ;
80
 
81
    ; Copy File from Remote Host to this machine
82
    call translateData  ; Convert Filename & IP address
83
    mov  edi, tftp_filename + 1
84
    mov  [edi], byte 0x01 ; setup tftp msg
85
    call copyFromRemote
86
 
87
    jmp  still
88
 
89
nocopyl:
90
 
91
    cmp  ah,3        ; Copy file to host?
92
    jnz  nocopyh
93
 
94
    mov   dword [prompt], p5
95
    mov  dword [promptlen], p5len - p5
96
    call  draw_window            ;
97
 
98
    ; Copy File from this machine to Remote Host
99
    call translateData  ; Convert Filename & IP address
100
    mov  edi, tftp_filename + 1
101
    mov  [edi], byte 0x02 ; setup tftp msg
102
    call copyToRemote
103
 
104
    jmp  still
105
 
106
nocopyh:
107
    cmp  ah,4
108
    jz   f1
109
    cmp  ah,5
110
    jz   f2
111
    jmp  nof12
112
 
113
  f1:
114
    mov  [addr],dword source
115
    mov  [ya],dword 35
116
    jmp  rk
117
 
118
  f2:
119
    mov  [addr],dword destination
120
    mov  [ya],dword 35+16
121
 
122
  rk:
123
    mov  ecx,15
124
    mov  edi,[addr]
125
    mov  al,' '
126
    rep  stosb
127
 
128
    call print_text
129
 
130
    mov  edi,[addr]
131
 
132
  f11:
133
    mov  eax,10
134
    int  0x40
135
    cmp  eax,2
136
    jz   fbu
137
    jmp  still
138
  fbu:
139
    mov  eax,2
140
    int  0x40  ; get key
141
    shr  eax,8
142
    cmp  eax,8
143
    jnz  nobs
144
    cmp  edi,[addr]
145
    jz   f11
146
    sub  edi,1
147
    mov  [edi],byte ' '
148
    call print_text
149
    jmp  f11
150
  nobs:
151
    cmp  eax,dword 31
152
    jbe  f11
153
    cmp  eax,dword 95
154
    jb   keyok
155
    sub  eax,32
156
  keyok:
157
    mov  [edi],al
158
 
159
    call print_text
160
 
161
    add  edi,1
162
    mov  esi,[addr]
163
    add  esi,15
164
    cmp  esi,edi
165
    jnz  f11
166
 
167
    jmp  still
168
 
169
print_text:
170
 
171
    mov  eax,13
172
    mov  ebx,103*65536+15*6
173
    mov  ecx,[ya]
174
    shl  ecx,16
175
    mov  cx,8
176
    mov  edx,0x224466
177
    int  0x40
178
 
179
    mov  eax,4
180
    mov  ebx,103*65536
181
    add  ebx,[ya]
182
    mov  ecx,0xffffff
183
    mov  edx,[addr]
184
    mov  esi,15
185
    int  0x40
186
 
187
    ret
188
 
189
 
190
  nof12:
191
    jmp  still
192
 
193
 
194
;***************************************************************************
195
;   Function
196
;      translateData
197
;
198
;   Description
199
;      Coverts the filename and IP address typed in by the user into
200
;      a format suitable for the IP layer.
201
;
202
;    The filename, in source, is converted and stored in tftp_filename
203
;      The host ip, in destination, is converted and stored in tftp_IP
204
;
205
;***************************************************************************
206
translateData:
207
 
208
 ; first, build up the tftp command string. This includes the filename
209
 ; and the transfer protocol
210
 
211
 
212
 ; First, write 0,0
213
 mov  al, 0
214
 mov  edi, tftp_filename
215
 mov  [edi], al
216
 inc  edi
217
 mov  [edi], al
218
 inc  edi
219
 
220
 ; Now, write the file name itself, and null terminate it
221
 mov  ecx, 15
222
 mov  ah, ' '
223
 mov  esi, source
224
 
225
td001:
226
 lodsb
227
 stosb
228
 cmp  al, ah
229
 loopnz td001
230
 
231
 cmp  al,ah  ; Was the entire buffer full of characters?
232
 jne  td002
233
 dec  edi   ; No - so remove ' ' character
234
 
235
td002:
236
 mov  [edi], byte 0
237
 inc  edi
238
 mov  [edi], byte 'O'
239
 inc  edi
240
 mov  [edi], byte 'C'
241
 inc  edi
242
 mov  [edi], byte 'T'
243
 inc  edi
244
 mov  [edi], byte 'E'
245
 inc  edi
246
 mov  [edi], byte 'T'
247
 inc  edi
248
 mov  [edi], byte 0
249
 
250
 mov  esi, tftp_filename
251
 sub  edi, esi
252
 mov  [tftp_len], edi
253
 
254
 
255
 ; Now, convert the typed IP address into a real address
256
 ; No validation is done on the number entered
257
 ; ip addresses must be typed in normally, eg
258
 ; 192.1.45.24
259
 
260
 xor  eax, eax
261
 mov  dh, 10
262
 mov  dl, al
263
 mov  [tftp_IP], eax
264
 
265
 ; 192.168.24.1   1.1.1.1       1. 9.2.3.
266
 
267
 mov  esi, destination
268
 mov  edi, tftp_IP
269
 
270
 mov  ecx, 4
271
 
272
td003:
273
 lodsb
274
 sub  al, '0'
275
 add  dl, al
276
 lodsb
277
 cmp  al, '.'
278
 je  ipNext
279
 cmp  al, ' '
280
 je  ipNext
281
 mov  dh, al
282
 sub  dh, '0'
283
 mov  al, 10
284
 mul  dl
285
 add  al, dh
286
 mov  dl, al
287
 lodsb
288
 cmp  al, '.'
289
 je  ipNext
290
 cmp  al, ' '
291
 je  ipNext
292
 mov  dh, al
293
 sub  dh, '0'
294
 mov  al, 10
295
 mul  dl
296
 add  al, dh
297
 mov  dl, al
298
 lodsb
299
 
300
ipNext:
301
 mov  [edi], dl
302
 inc  edi
303
 mov  dl, 0
304
 loop td003
305
 
306
 ret
307
 
308
 
309
 
310
;***************************************************************************
311
;   Function
312
;      copyFromRemote
313
;
314
;   Description
315
;
316
;***************************************************************************
317
copyFromRemote:
318
 xor  eax, eax
319
 mov  [filesize], eax
320
 mov  eax, I_END + 512 ; This is the point where the file buffer is
321
 mov  [fileposition], eax
322
 
323
 ; Get a random # for the local socket port #
324
 mov  eax, 3
325
 int     0x40
326
 mov  ecx, eax
327
 shr  ecx, 8    ; Set up the local port # with a random #
328
 
329
   ; open socket
330
 mov  eax, 53
331
 mov  ebx, 0
332
 mov  edx, 69    ; remote port
333
 mov  esi, [tftp_IP]  ; remote IP ( in intenet format )
334
    int   0x40
335
 
336
   mov  [socketNum], eax
337
 
338
 ; make sure there is no data in the socket - there shouldn't be..
339
 
340
cfr001:
341
 mov  eax, 53
342
 mov  ebx, 3
343
 mov  ecx, [socketNum]
344
    int   0x40    ; read byte
345
 
346
 mov  eax, 53
347
 mov  ebx, 2
348
 mov  ecx, [socketNum]
349
    int   0x40    ; any more data?
350
 
351
 cmp  eax, 0
352
 jne  cfr001    ; yes, so get it
353
 
354
 ; Now, request the file
355
 mov  eax, 53
356
 mov  ebx, 4
357
 mov  ecx, [socketNum]
358
 mov  edx, [tftp_len]
359
 mov  esi, tftp_filename
360
    int   0x40
361
 
362
cfr002:
363
    mov  eax,10                 ; wait here for event
364
    int  0x40
365
 
366
    cmp  eax,1                  ; redraw request ?
367
    je   cfr003
368
    cmp  eax,2                  ; key in buffer ?
369
    je   cfr004
370
    cmp  eax,3                  ; button in buffer ?
371
    je   cfr005
372
 
373
    ; Any data to fetch?
374
 mov  eax, 53
375
 mov  ebx, 2
376
 mov  ecx, [socketNum]
377
    int   0x40
378
 
379
 cmp  eax, 0
380
 je  cfr002
381
 
382
 push eax     ; eax holds # chars
383
 
384
 ; Update the text on the display - once
385
 mov  eax, [prompt]
386
 cmp  eax, p3
387
 je  cfr008
388
    mov   dword [prompt], p3
389
    mov  dword [promptlen], p3len - p3
390
    call  draw_window            ;
391
 
392
cfr008:
393
 ; we have data - this will be a tftp frame
394
 
395
 ; read first two bytes - opcode
396
 mov  eax, 53
397
 mov  ebx, 3
398
 mov  ecx, [socketNum]
399
    int   0x40   ; read byte
400
 
401
 mov  eax, 53
402
 mov  ebx, 3
403
 mov  ecx, [socketNum]
404
    int   0x40   ; read byte
405
 
406
 pop  eax
407
 ; bl holds tftp opcode. Can only be 3 (data) or 5 ( error )
408
 
409
 cmp  bl, 3
410
 jne  cfrerr
411
 
412
 push eax
413
 
414
 ; do data stuff. Read block #. Read data. Send Ack.
415
 mov  eax, 53
416
 mov  ebx, 3
417
 mov  ecx, [socketNum]
418
    int   0x40   ; read byte
419
 
420
 mov  [blockNumber], bl
421
 
422
 mov  eax, 53
423
 mov  ebx, 3
424
 mov  ecx, [socketNum]
425
 int   0x40   ; read byte
426
 
427
 mov  [blockNumber+1], bl
428
 
429
cfr007:
430
 
431
 mov  eax, 53
432
 mov  ebx, 2
433
 mov  ecx, [socketNum]
434
 int  0x40   ; any more data?
435
 
436
 cmp  eax, 0
437
 je   no_more_data ; no
438
 
439
 mov  eax, 53
440
 mov  ebx, 3
441
 mov  ecx, [socketNum]
442
 int  0x40   ; read byte
443
 
444
 mov  esi, [fileposition]
445
 mov  [esi], bl
446
 inc  dword [fileposition]
447
 inc  dword [filesize]
448
 
449
 jmp  cfr007
450
 
451
no_more_data:
452
 
453
 ; write the block number into the ack
454
 mov  al, [blockNumber]
455
 mov  [ack + 2], al
456
 
457
 mov  al, [blockNumber+1]
458
 mov  [ack + 3], al
459
 
460
 ; send an 'ack'
461
 mov  eax, 53
462
 mov  ebx, 4
463
 mov  ecx, [socketNum]
464
 mov  edx, ackLen - ack
465
 mov  esi, ack
466
    int   0x40
467
 
468
 ; If # of chars in the frame is less that 516,
469
 ; this frame is the last
470
 pop  eax
471
 cmp  eax, 516
472
 je  cfr002
473
 
474
 ; Write the file
475
 mov  eax, 33
476
 mov  ebx, source
477
 mov  edx, [filesize]
478
 mov  ecx, I_END + 512
479
 mov  esi, 0
480
 int  0x40
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
    int  0x40
508
    jmp  cfr002
509
 
510
cfr005:                        ; button
511
    mov  eax,17                 ; get id
512
    int  0x40
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
    int  0x40
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
    int  0x40
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,0x03224466            ; color of work area RRGGBB
823
    mov  esi,0x00334455            ; color of grab bar  RRGGBB,8->color gl
824
    mov  edi,0x00ddeeff            ; color of frames    RRGGBB
825
    int  0x40
826
 
827
                                   ; WINDOW LABEL
828
    mov  eax,4                     ; function 4 : write text to window
829
    mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
830
    mov  ecx,0x00ffffff            ; color of text RRGGBB
831
    mov  edx,labelt                ; pointer to text beginning
832
    mov  esi,labellen-labelt       ; text length
833
    int  0x40
834
 
835
 
836
    mov  eax,8              ; COPY BUTTON
837
    mov  ebx,20*65536+190
838
    mov  ecx,79*65536+15
839
    mov  edx,2
840
    mov  esi,0x557799
841
    int  0x40
842
 
843
    mov  eax,8              ; DELETE BUTTON
844
    mov  ebx,20*65536+190
845
    mov  ecx,111*65536+15
846
    mov  edx,3
847
    mov  esi,0x557799
848
    int  0x40
849
 
850
    mov  eax,8
851
    mov  ebx,200*65536+10
852
    mov  ecx,34*65536+10
853
    mov  edx,4
854
    mov  esi,0x557799
855
    int  0x40
856
 
857
    mov  eax,8
858
    mov  ebx,200*65536+10
859
    mov  ecx,50*65536+10
860
    mov  edx,5
861
    mov  esi,0x557799
862
    int  0x40
863
 
864
 
865
 ; Copy the file name to the screen buffer
866
 ; file name is same length as IP address, to
867
 ; make the math easier later.
868
    cld
869
    mov  esi,source
870
    mov  edi,text+13
871
    mov  ecx,15
872
    rep  movsb
873
 
874
 
875
 ; copy the IP address to the screen buffer
876
    mov  esi,destination
877
    mov  edi,text+40+13
878
    mov  ecx,15
879
    rep  movsb
880
 
881
  ; copy the prompt to the screen buffer
882
    mov  esi,[prompt]
883
    mov  edi,text+280
884
    mov  ecx,[promptlen]
885
    rep  movsb
886
 
887
    ; Re-draw the screen text
888
    cld
889
    mov  ebx,25*65536+35           ; draw info text with function 4
890
    mov  ecx,0xffffff
891
    mov  edx,text
892
    mov  esi,40
893
  newline:
894
    mov  eax,4
895
    int  0x40
896
    add  ebx,16
897
    add  edx,40
898
    cmp  [edx],byte 'x'
899
    jnz  newline
900
 
901
 
902
    mov  eax,12                    ; function 12:tell os about windowdraw
903
    mov  ebx,2                     ; 2, end of draw
904
    int  0x40
905
 
906
    ret
907
 
908
 
909
; DATA AREA
910
 
911
source       db  'KERNEL.ASM     '
912
destination  db  '192.168.1.23   '
913
 
914
 
915
tftp_filename:  times 15 + 9 db 0
916
tftp_IP:   dd 0
917
tftp_len:   dd 0
918
 
919
addr  dd  0x0
920
ya    dd  0x0
921
 
922
fileposition dd 0 ; Points to the current point in the file
923
filesize  dd 0 ; The number of bytes written / left to write
924
fileblocksize dw 0 ; The number of bytes to send in this frame
925
 
926
text:
927
    db 'SOURCE FILE: xxxxxxxxxxxxxxx            '
928
    db 'HOST IP ADD: xxx.xxx.xxx.xxx            '
929
    db '                                        '
930
    db '  COPY HOST   ->   LOCAL                '
931
    db '                                        '
932
    db '  COPY LOCAL  ->   HOST                 '
933
    db '                                        '
934
    db '                                        '
935
    db 'x <- END MARKER, DONT DELETE            '
936
 
937
 
938
labelt:
939
    db   'TFTP Client'
940
labellen:
941
 
942
 
943
prompt: dd 0
944
promptlen: dd 0
945
 
946
 
947
p1:  db 'Waiting for Command'
948
p1len:
949
 
950
p2:  db 'Sending File       '
951
p2len:
952
 
953
p3:  db 'Receiving File     '
954
p3len:
955
 
956
p4:  db 'Tranfer Complete   '
957
p4len:
958
 
959
p5:  db 'Contacting Host... '
960
p5len:
961
 
962
p6:  db 'File not found.    '
963
p6len:
964
 
965
ack:
966
 db 00,04,0,1
967
ackLen:
968
 
969
socketNum:
970
 dd 0
971
 
972
blockNumber:
973
 dw 0
974
 
975
; This must be the last part of the file, because the blockBuffer
976
; continues at I_END.
977
blockBuffer:
978
 db 00, 03, 00, 01
979
I_END:
980