Subversion Repositories Kolibri OS

Rev

Rev 331 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;    TFTP Client
3
 
4
use32
331 heavyiron 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
31 halyavin 13
 
14
include 'lang.inc'
485 heavyiron 15
include '..\..\..\macros.inc'
31 halyavin 16
 
331 heavyiron 17
START:				; start of execution
18
     mov  eax,40		 ; Report events
19
     mov  ebx,10000111b 	 ; Stack 8 + defaults
485 heavyiron 20
     mcall
31 halyavin 21
 
22
    mov   dword [prompt], p1
23
    mov  dword [promptlen], p1len - p1
485 heavyiron 24
 
25
red:
331 heavyiron 26
    call draw_window		; at first, draw the window
31 halyavin 27
 
28
still:
331 heavyiron 29
    mov  eax,10 		; wait here for event
485 heavyiron 30
    mcall
31 halyavin 31
 
331 heavyiron 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
31 halyavin 38
 
39
    jmp  still
485 heavyiron 40
 
331 heavyiron 41
key:			       ; Keys are not valid at this part of the
42
    mov  eax,2			; loop. Just read it and ignore
485 heavyiron 43
    mcall
31 halyavin 44
    jmp  still
45
 
331 heavyiron 46
button: 		       ; button
47
    mov  eax,17 		; get id
485 heavyiron 48
    mcall
31 halyavin 49
 
331 heavyiron 50
    cmp  ah,1			; button id=1 ?
31 halyavin 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
 
485 heavyiron 63
    or  eax,-1 	; close this program
64
    mcall
31 halyavin 65
 
66
noclose:
331 heavyiron 67
    cmp  ah,2			; copy file to local machine?
31 halyavin 68
    jnz  nocopyl
69
 
70
    mov   dword [prompt], p5
71
    mov  dword [promptlen], p5len - p5
331 heavyiron 72
    call  draw_window		 ;
31 halyavin 73
 
74
    ; Copy File from Remote Host to this machine
331 heavyiron 75
    call translateData	; Convert Filename & IP address
31 halyavin 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
 
331 heavyiron 84
    cmp  ah,3	     ; Copy file to host?
31 halyavin 85
    jnz  nocopyh
86
 
87
    mov   dword [prompt], p5
88
    mov  dword [promptlen], p5len - p5
331 heavyiron 89
    call  draw_window		 ;
31 halyavin 90
 
91
    ; Copy File from this machine to Remote Host
331 heavyiron 92
    call translateData	; Convert Filename & IP address
31 halyavin 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
331 heavyiron 101
    jz	 f1
31 halyavin 102
    cmp  ah,5
331 heavyiron 103
    jz	 f2
31 halyavin 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
485 heavyiron 127
    mcall
31 halyavin 128
    cmp  eax,2
331 heavyiron 129
    jz	 fbu
31 halyavin 130
    jmp  still
131
  fbu:
132
    mov  eax,2
485 heavyiron 133
    mcall  ; get key
31 halyavin 134
    shr  eax,8
135
    cmp  eax,8
136
    jnz  nobs
137
    cmp  edi,[addr]
331 heavyiron 138
    jz	 f11
31 halyavin 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
331 heavyiron 147
    jb	 keyok
31 halyavin 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
485 heavyiron 170
    mcall
31 halyavin 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
485 heavyiron 178
    mcall
31 halyavin 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
331 heavyiron 318
 int	 0x40
31 halyavin 319
 mov  ecx, eax
331 heavyiron 320
 shr  ecx, 8	; Set up the local port # with a random #
31 halyavin 321
 
322
   ; open socket
323
 mov  eax, 53
324
 mov  ebx, 0
331 heavyiron 325
 mov  edx, 69	 ; remote port
31 halyavin 326
 mov  esi, [tftp_IP]  ; remote IP ( in intenet format )
327
    int   0x40
328
 
331 heavyiron 329
   mov	[socketNum], eax
31 halyavin 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]
331 heavyiron 337
    int   0x40	  ; read byte
31 halyavin 338
 
339
 mov  eax, 53
340
 mov  ebx, 2
341
 mov  ecx, [socketNum]
331 heavyiron 342
    int   0x40	  ; any more data?
31 halyavin 343
 
344
 cmp  eax, 0
331 heavyiron 345
 jne  cfr001	; yes, so get it
31 halyavin 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:
331 heavyiron 356
    mov  eax,10 		; wait here for event
485 heavyiron 357
    mcall
31 halyavin 358
 
331 heavyiron 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
31 halyavin 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
331 heavyiron 383
    call  draw_window		 ;
31 halyavin 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]
331 heavyiron 392
    int   0x40	 ; read byte
31 halyavin 393
 
394
 mov  eax, 53
395
 mov  ebx, 3
396
 mov  ecx, [socketNum]
331 heavyiron 397
    int   0x40	 ; read byte
31 halyavin 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]
331 heavyiron 411
    int   0x40	 ; read byte
31 halyavin 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]
485 heavyiron 427
 mcall   ; any more data?
31 halyavin 428
 
429
 cmp  eax, 0
430
 je   no_more_data ; no
431
 
432
 mov  eax, 53
433
 mov  ebx, 3
434
 mov  ecx, [socketNum]
485 heavyiron 435
 mcall   ; read byte
31 halyavin 436
 
437
 mov  esi, [fileposition]
438
 mov  [esi], bl
439
 inc  dword [fileposition]
440
 inc  dword [filesize]
441
 
331 heavyiron 442
 jmp  cfr007
31 halyavin 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
485 heavyiron 473
 mcall
31 halyavin 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]
331 heavyiron 482
    int   0x40	  ; read byte
31 halyavin 483
 
484
 mov  eax, 53
485
 mov  ebx, 2
486
 mov  ecx, [socketNum]
331 heavyiron 487
    int   0x40	  ; any more data?
31 halyavin 488
 
489
 cmp  eax, 0
331 heavyiron 490
 jne  cfrerr	; yes, so get it
31 halyavin 491
 
331 heavyiron 492
 jmp  cfr006	; close socket and close app
31 halyavin 493
 
331 heavyiron 494
cfr003: 			; redraw request
31 halyavin 495
    call draw_window
496
    jmp  cfr002
497
 
331 heavyiron 498
cfr004: 			; key pressed
499
    mov  eax,2			; just read it and ignore
485 heavyiron 500
    mcall
31 halyavin 501
    jmp  cfr002
502
 
331 heavyiron 503
cfr005: 		       ; button
504
    mov  eax,17 		; get id
485 heavyiron 505
    mcall
31 halyavin 506
 
331 heavyiron 507
    cmp  ah,1			; button id=1 ?
31 halyavin 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
 
331 heavyiron 519
    mov  eax,-1 		; close this program
485 heavyiron 520
    mcall
31 halyavin 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
331 heavyiron 535
    call  draw_window		 ;
31 halyavin 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
331 heavyiron 561
    call  draw_window		 ;
31 halyavin 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
331 heavyiron 583
 int	 0x40
31 halyavin 584
 mov  ecx, eax
331 heavyiron 585
 shr  ecx, 8	; Set up the local port # with a random #
31 halyavin 586
 
587
   ; First, open socket
588
 mov  eax, 53
589
 mov  ebx, 0
331 heavyiron 590
 mov  edx, 69	 ; remote port
31 halyavin 591
 mov  esi, [tftp_IP]
592
    int   0x40
593
 
331 heavyiron 594
   mov	[socketNum], eax
31 halyavin 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:
331 heavyiron 610
    mov   eax,10		 ; wait here for event
31 halyavin 611
    int   0x40
612
 
331 heavyiron 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
31 halyavin 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
331 heavyiron 637
    call  draw_window		 ;
31 halyavin 638
 
639
 ; we have data - this will be the ack
640
ctr002:
641
 mov  eax, 53
642
 mov  ebx, 3
643
 mov  ecx, [socketNum]
331 heavyiron 644
    int   0x40	 ; read byte - opcode
31 halyavin 645
 
646
 mov  eax, 53
647
 mov  ebx, 3
648
 mov  ecx, [socketNum]
331 heavyiron 649
    int   0x40	 ; read byte - opcode
31 halyavin 650
 
651
 mov  eax, 53
652
 mov  ebx, 3
653
 mov  ecx, [socketNum]
331 heavyiron 654
    int   0x40	 ; read byte - block (high byte)
31 halyavin 655
 
656
 mov  [blockNumber], bl
657
 
658
 mov  eax, 53
659
 mov  ebx, 3
660
 mov  ecx, [socketNum]
331 heavyiron 661
    int   0x40	 ; read byte - block (low byte )
31 halyavin 662
 
663
 mov  [blockNumber+1], bl
664
 
665
ctr0022:
666
 mov  eax, 53
667
 mov  ebx, 3
668
 mov  ecx, [socketNum]
331 heavyiron 669
    int   0x40	 ; read byte (shouldn't have worked)
31 halyavin 670
 
671
 
672
 mov  eax, 53
673
 mov  ebx, 2
674
 mov  ecx, [socketNum]
331 heavyiron 675
    int   0x40	 ; any more data?
31 halyavin 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
331 heavyiron 699
 inc	 byte [esi]
31 halyavin 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
 
331 heavyiron 755
ctr003: 		; redraw
31 halyavin 756
    call  draw_window
757
    jmp   ctr001
758
 
331 heavyiron 759
ctr004: 		; key
760
    mov   eax,2 	 ; just read it and ignore
31 halyavin 761
    int   0x40
762
    jmp   ctr001
763
 
331 heavyiron 764
ctr005: 		; button
765
    mov   eax,17	 ; get id
31 halyavin 766
    int   0x40
767
 
331 heavyiron 768
    cmp   ah,1		 ; button id=1 ?
31 halyavin 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
 
331 heavyiron 779
    mov   eax,-1	 ; close this program
31 halyavin 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
331 heavyiron 792
    call  draw_window		 ;
31 halyavin 793
 
794
ctr_exit:
795
 ret
796
 
797
 
798
 
799
 
800
;   *********************************************
801
;   *******  WINDOW DEFINITIONS AND DRAW ********
802
;   *********************************************
803
 
804
 
805
draw_window:
806
 
331 heavyiron 807
    mov  eax,12 		   ; function 12:tell os about windowdraw
808
    mov  ebx,1			   ; 1, start of draw
485 heavyiron 809
    mcall
31 halyavin 810
 
331 heavyiron 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,0x13224466 	   ; color of work area RRGGBB
485 heavyiron 816
    mov  edi,title
817
    mcall
31 halyavin 818
 
331 heavyiron 819
    mov  eax,8		    ; COPY BUTTON
31 halyavin 820
    mov  ebx,20*65536+190
821
    mov  ecx,79*65536+15
822
    mov  edx,2
823
    mov  esi,0x557799
485 heavyiron 824
    mcall
31 halyavin 825
 
485 heavyiron 826
 ;   mov  eax,8		    ; DELETE BUTTON
31 halyavin 827
    mov  ebx,20*65536+190
828
    mov  ecx,111*65536+15
829
    mov  edx,3
485 heavyiron 830
    mcall
31 halyavin 831
 
485 heavyiron 832
 ;   mov  eax,8
833
 ;   mov  ebx,200*65536+10
31 halyavin 834
    mov  ecx,34*65536+10
835
    mov  edx,4
485 heavyiron 836
    mcall
31 halyavin 837
 
485 heavyiron 838
 ;   mov  eax,8
839
 ;   mov  ebx,200*65536+10
31 halyavin 840
    mov  ecx,50*65536+10
841
    mov  edx,5
485 heavyiron 842
    mcall
31 halyavin 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
485 heavyiron 869
    mov  eax,4
331 heavyiron 870
    mov  ebx,25*65536+35	   ; draw info text with function 4
31 halyavin 871
    mov  ecx,0xffffff
872
    mov  edx,text
873
    mov  esi,40
874
  newline:
485 heavyiron 875
    mcall
31 halyavin 876
    add  ebx,16
877
    add  edx,40
878
    cmp  [edx],byte 'x'
879
    jnz  newline
880
 
881
 
331 heavyiron 882
    mov  eax,12 		   ; function 12:tell os about windowdraw
883
    mov  ebx,2			   ; 2, end of draw
485 heavyiron 884
    mcall
31 halyavin 885
 
886
    ret
887
 
888
 
889
; DATA AREA
890
 
331 heavyiron 891
source	     db  'KERNEL.ASM     '
31 halyavin 892
destination  db  '192.168.1.23   '
893
 
894
 
331 heavyiron 895
tftp_filename:	times 15 + 9 db 0
31 halyavin 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 '                                        '
331 heavyiron 915
    db 'x' ; <- END MARKER, DONT DELETE
31 halyavin 916
 
917
 
485 heavyiron 918
title	db   'TFTP Client',0
31 halyavin 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