Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 485 Rev 551
1
;
1
;
2
;    TFTP Wave Player
2
;    TFTP Wave Player
3
;
3
;
4
;    Compile with FASM for Menuet
4
;    Compile with FASM for Menuet
5
;
5
;
6
;
6
;
7
;    12.7.2002 - Audio system calls by VT
7
;    12.7.2002 - Audio system calls by VT
8
;
8
;
9
   
9
   
10
use32
10
use32
11
 org	0x0
11
 org	0x0
12
 db	'MENUET01'    ; header
12
 db	'MENUET01'    ; header
13
 dd	0x01	      ; header version
13
 dd	0x01	      ; header version
14
 dd	START	      ; entry point
14
 dd	START	      ; entry point
15
 dd	I_END	      ; image size
15
 dd	I_END	      ; image size
16
 dd	I_END+0x10000 ; required memory
16
 dd	I_END+0x10000 ; required memory
17
 dd	I_END+0x10000 ; esp
17
 dd	I_END+0x10000 ; esp
18
 dd	0x0 , 0x0     ; I_Param , I_Path
18
 dd	0x0 , 0x0     ; I_Param , I_Path
19
 
19
 
20
include 'lang.inc'
20
include 'lang.inc'
21
include '..\..\..\macros.inc'
21
include '..\..\..\macros.inc'
22
   
22
   
23
delay	   dd  145
23
delay	   dd  145
24
wait_for   dd  0x0
24
wait_for   dd  0x0
25
   
25
   
26
START:				; start of execution
26
START:				; start of execution
27
   
27
   
28
    mov  dword [prompt], p9
28
    mov  dword [prompt], p9
29
    mov  dword [promptlen], p9len - p9
29
    mov  dword [promptlen], p9len - p9
30
 
30
 
31
red:   
31
red:   
32
    call draw_window		; at first, draw the window
32
    call draw_window		; at first, draw the window
33
   
33
   
34
still:
34
still:
35
   
35
   
36
    mov  eax,10 		; wait here for event
36
    mov  eax,10 		; wait here for event
37
    mcall
37
    mcall
38
   
38
   
39
    cmp  eax,1			; redraw request ?
39
    cmp  eax,1			; redraw request ?
40
    jz	 red
40
    jz	 red
41
    cmp  eax,2			; key in buffer ?
41
    cmp  eax,2			; key in buffer ?
42
    jz	 key
42
    jz	 key
43
    cmp  eax,3			; button in buffer ?
43
    cmp  eax,3			; button in buffer ?
44
    jz	 button
44
    jz	 button
45
   
45
   
46
    jmp  still
46
    jmp  still
47
key:			       ; Keys are not valid at this part of the
47
key:			       ; Keys are not valid at this part of the
48
    mov  eax,2			; loop. Just read it and ignore
48
    mov  eax,2			; loop. Just read it and ignore
49
    mcall
49
    mcall
50
    jmp  still
50
    jmp  still
51
   
51
   
52
button: 		       ; button
52
button: 		       ; button
53
    mov  eax,17 		; get id
53
    mov  eax,17 		; get id
54
    mcall
54
    mcall
55
   
55
   
56
    cmp  ah,1			; button id=1 ?
56
    cmp  ah,1			; button id=1 ?
57
    jnz  noclose
57
    jnz  noclose
58
   
58
   
59
   
59
   
60
    ; close socket before exiting
60
    ; close socket before exiting
61
 mov  eax, 53
61
 mov  eax, 53
62
 mov  ebx, 1
62
 mov  ebx, 1
63
 mov  ecx, [socketNum]
63
 mov  ecx, [socketNum]
64
    mcall
64
    mcall
65
   
65
   
66
 mov  [socketNum], dword 0
66
 mov  [socketNum], dword 0
67
   
67
   
68
   
68
   
69
    or  eax,-1 	; close this program
69
    or  eax,-1 	; close this program
70
    mcall
70
    mcall
71
   
71
   
72
noclose:
72
noclose:
73
    cmp  ah,2			; copy file to local machine?
73
    cmp  ah,2			; copy file to local machine?
74
    jnz  nocopyl
74
    jnz  nocopyl
75
   
75
   
76
    mov   dword [prompt], p5
76
    mov   dword [prompt], p5
77
    mov  dword [promptlen], p5len - p5
77
    mov  dword [promptlen], p5len - p5
78
    call  draw_window		 ;
78
    call  draw_window		 ;
79
   
79
   
80
    ; Copy File from Remote Host to this machine
80
    ; Copy File from Remote Host to this machine
81
    call translateData	; Convert Filename & IP address
81
    call translateData	; Convert Filename & IP address
82
    mov  edi, tftp_filename + 1
82
    mov  edi, tftp_filename + 1
83
    mov  [edi], byte 0x01 ; setup tftp msg
83
    mov  [edi], byte 0x01 ; setup tftp msg
84
    call copyFromRemote
84
    call copyFromRemote
85
   
85
   
86
    jmp  still
86
    jmp  still
87
   
87
   
88
nocopyl:
88
nocopyl:
89
   
89
   
90
   
90
   
91
    cmp  ah,4
91
    cmp  ah,4
92
    jz	 f1
92
    jz	 f1
93
    cmp  ah,5
93
    cmp  ah,5
94
    jz	 f2
94
    jz	 f2
95
    jmp  nof12
95
    jmp  nof12
96
   
96
   
97
  f1:
97
  f1:
98
    mov  [addr],dword source
98
    mov  [addr],dword source
99
    mov  [ya],dword 35
99
    mov  [ya],dword 35
100
    jmp  rk
100
    jmp  rk
101
   
101
   
102
  f2:
102
  f2:
103
    mov  [addr],dword destination
103
    mov  [addr],dword destination
104
    mov  [ya],dword 35+16
104
    mov  [ya],dword 35+16
105
   
105
   
106
  rk:
106
  rk:
107
    mov  ecx,15
107
    mov  ecx,15
108
    mov  edi,[addr]
108
    mov  edi,[addr]
109
    mov  al,' '
109
    mov  al,' '
110
    rep  stosb
110
    rep  stosb
111
   
111
   
112
    call print_text
112
    call print_text
113
   
113
   
114
    mov  edi,[addr]
114
    mov  edi,[addr]
115
   
115
   
116
  f11:
116
  f11:
117
    mov  eax,10
117
    mov  eax,10
118
    mcall
118
    mcall
119
    cmp  eax,2
119
    cmp  eax,2
120
    jz	 fbu
120
    jz	 fbu
121
    jmp  still
121
    jmp  still
122
  fbu:
122
  fbu:
123
    mov  eax,2
123
    mov  eax,2
124
    mcall  ; get key
124
    mcall  ; get key
125
    shr  eax,8
125
    shr  eax,8
126
    cmp  eax,8
126
    cmp  eax,8
127
    jnz  nobs
127
    jnz  nobs
128
    cmp  edi,[addr]
128
    cmp  edi,[addr]
129
    jz	 f11
129
    jz	 f11
130
    sub  edi,1
130
    sub  edi,1
131
    mov  [edi],byte ' '
131
    mov  [edi],byte ' '
132
    call print_text
132
    call print_text
133
    jmp  f11
133
    jmp  f11
134
  nobs:
134
  nobs:
135
    cmp  eax,dword 31
135
    cmp  eax,dword 31
136
    jbe  f11
136
    jbe  f11
137
    cmp  eax,dword 95
137
    cmp  eax,dword 95
138
    jb	 keyok
138
    jb	 keyok
139
    sub  eax,32
139
    sub  eax,32
140
  keyok:
140
  keyok:
141
    mov  [edi],al
141
    mov  [edi],al
142
   
142
   
143
    call print_text
143
    call print_text
144
   
144
   
145
    add  edi,1
145
    add  edi,1
146
    mov  esi,[addr]
146
    mov  esi,[addr]
147
    add  esi,15
147
    add  esi,15
148
    cmp  esi,edi
148
    cmp  esi,edi
149
    jnz  f11
149
    jnz  f11
150
   
150
   
151
    jmp  still
151
    jmp  still
152
   
152
   
153
print_text:
153
print_text:
154
   
154
   
155
    mov  eax,13
155
    mov  eax,13
156
    mov  ebx,103*65536+15*6
156
    mov  ebx,103*65536+15*6
157
    mov  ecx,[ya]
157
    mov  ecx,[ya]
158
    shl  ecx,16
158
    shl  ecx,16
159
    mov  cx,8
159
    mov  cx,8
160
    mov  edx,0x224466
160
    mov  edx,0x224466
161
    mcall
161
    mcall
162
   
162
   
163
    mov  eax,4
163
    mov  eax,4
164
    mov  ebx,103*65536
164
    mov  ebx,103*65536
165
    add  ebx,[ya]
165
    add  ebx,[ya]
166
    mov  ecx,0xffffff
166
    mov  ecx,0xffffff
167
    mov  edx,[addr]
167
    mov  edx,[addr]
168
    mov  esi,15
168
    mov  esi,15
169
    mcall
169
    mcall
170
   
170
   
171
    ret
171
    ret
172
   
172
   
173
   
173
   
174
  nof12:
174
  nof12:
175
    jmp  still
175
    jmp  still
176
   
176
   
177
   
177
   
178
;***************************************************************************
178
;***************************************************************************
179
;   Function
179
;   Function
180
;      translateData
180
;      translateData
181
;
181
;
182
;   Description
182
;   Description
183
;      Coverts the filename and IP address typed in by the user into
183
;      Coverts the filename and IP address typed in by the user into
184
;      a format suitable for the IP layer.
184
;      a format suitable for the IP layer.
185
;
185
;
186
;    The filename, in source, is converted and stored in tftp_filename
186
;    The filename, in source, is converted and stored in tftp_filename
187
;      The host ip, in destination, is converted and stored in tftp_IP
187
;      The host ip, in destination, is converted and stored in tftp_IP
188
;
188
;
189
;***************************************************************************
189
;***************************************************************************
190
translateData:
190
translateData:
191
   
191
   
192
 ; first, build up the tftp command string. This includes the filename
192
 ; first, build up the tftp command string. This includes the filename
193
 ; and the transfer protocol
193
 ; and the transfer protocol
194
   
194
   
195
   
195
   
196
 ; First, write 0,0
196
 ; First, write 0,0
197
 mov  al, 0
197
 mov  al, 0
198
 mov  edi, tftp_filename
198
 mov  edi, tftp_filename
199
 mov  [edi], al
199
 mov  [edi], al
200
 inc  edi
200
 inc  edi
201
 mov  [edi], al
201
 mov  [edi], al
202
 inc  edi
202
 inc  edi
203
   
203
   
204
 ; Now, write the file name itself, and null terminate it
204
 ; Now, write the file name itself, and null terminate it
205
 mov  ecx, 15
205
 mov  ecx, 15
206
 mov  ah, ' '
206
 mov  ah, ' '
207
 mov  esi, source
207
 mov  esi, source
208
   
208
   
209
td001:
209
td001:
210
 lodsb
210
 lodsb
211
 stosb
211
 stosb
212
 cmp  al, ah
212
 cmp  al, ah
213
 loopnz td001
213
 loopnz td001
214
   
214
   
215
 cmp  al,ah  ; Was the entire buffer full of characters?
215
 cmp  al,ah  ; Was the entire buffer full of characters?
216
 jne  td002
216
 jne  td002
217
 dec  edi   ; No - so remove ' ' character
217
 dec  edi   ; No - so remove ' ' character
218
   
218
   
219
td002:
219
td002:
220
 mov  [edi], byte 0
220
 mov  [edi], byte 0
221
 inc  edi
221
 inc  edi
222
 mov  [edi], byte 'O'
222
 mov  [edi], byte 'O'
223
 inc  edi
223
 inc  edi
224
 mov  [edi], byte 'C'
224
 mov  [edi], byte 'C'
225
 inc  edi
225
 inc  edi
226
 mov  [edi], byte 'T'
226
 mov  [edi], byte 'T'
227
 inc  edi
227
 inc  edi
228
 mov  [edi], byte 'E'
228
 mov  [edi], byte 'E'
229
 inc  edi
229
 inc  edi
230
 mov  [edi], byte 'T'
230
 mov  [edi], byte 'T'
231
 inc  edi
231
 inc  edi
232
 mov  [edi], byte 0
232
 mov  [edi], byte 0
233
   
233
   
234
 mov  esi, tftp_filename
234
 mov  esi, tftp_filename
235
 sub  edi, esi
235
 sub  edi, esi
236
 mov  [tftp_len], edi
236
 mov  [tftp_len], edi
237
   
237
   
238
   
238
   
239
 ; Now, convert the typed IP address into a real address
239
 ; Now, convert the typed IP address into a real address
240
 ; No validation is done on the number entered
240
 ; No validation is done on the number entered
241
 ; ip addresses must be typed in normally, eg
241
 ; ip addresses must be typed in normally, eg
242
 ; 192.1.45.24
242
 ; 192.1.45.24
243
   
243
   
244
 xor  eax, eax
244
 xor  eax, eax
245
 mov  dh, 10
245
 mov  dh, 10
246
 mov  dl, al
246
 mov  dl, al
247
 mov  [tftp_IP], eax
247
 mov  [tftp_IP], eax
248
   
248
   
249
 ; 192.168.24.1   1.1.1.1       1. 9.2.3.
249
 ; 192.168.24.1   1.1.1.1       1. 9.2.3.
250
   
250
   
251
 mov  esi, destination
251
 mov  esi, destination
252
 mov  edi, tftp_IP
252
 mov  edi, tftp_IP
253
   
253
   
254
 mov  ecx, 4
254
 mov  ecx, 4
255
   
255
   
256
td003:
256
td003:
257
 lodsb
257
 lodsb
258
 sub  al, '0'
258
 sub  al, '0'
259
 add  dl, al
259
 add  dl, al
260
 lodsb
260
 lodsb
261
 cmp  al, '.'
261
 cmp  al, '.'
262
 je  ipNext
262
 je  ipNext
263
 cmp  al, ' '
263
 cmp  al, ' '
264
 je  ipNext
264
 je  ipNext
265
 mov  dh, al
265
 mov  dh, al
266
 sub  dh, '0'
266
 sub  dh, '0'
267
 mov  al, 10
267
 mov  al, 10
268
 mul  dl
268
 mul  dl
269
 add  al, dh
269
 add  al, dh
270
 mov  dl, al
270
 mov  dl, al
271
 lodsb
271
 lodsb
272
 cmp  al, '.'
272
 cmp  al, '.'
273
 je  ipNext
273
 je  ipNext
274
 cmp  al, ' '
274
 cmp  al, ' '
275
 je  ipNext
275
 je  ipNext
276
 mov  dh, al
276
 mov  dh, al
277
 sub  dh, '0'
277
 sub  dh, '0'
278
 mov  al, 10
278
 mov  al, 10
279
 mul  dl
279
 mul  dl
280
 add  al, dh
280
 add  al, dh
281
 mov  dl, al
281
 mov  dl, al
282
 lodsb
282
 lodsb
283
   
283
   
284
ipNext:
284
ipNext:
285
 mov  [edi], dl
285
 mov  [edi], dl
286
 inc  edi
286
 inc  edi
287
 mov  dl, 0
287
 mov  dl, 0
288
 loop td003
288
 loop td003
289
   
289
   
290
 ret
290
 ret
291
   
291
   
292
   
292
   
293
   
293
   
294
;***************************************************************************
294
;***************************************************************************
295
;   Function
295
;   Function
296
;      copyFromRemote
296
;      copyFromRemote
297
;
297
;
298
;   Description
298
;   Description
299
;
299
;
300
;***************************************************************************
300
;***************************************************************************
301
copyFromRemote:
301
copyFromRemote:
302
   
302
   
303
 mov  eax,0x20000-512
303
 mov  eax,0x20000-512
304
 mov  [fileposition], eax
304
 mov  [fileposition], eax
305
   
305
   
306
 ; Get a random # for the local socket port #
306
 ; Get a random # for the local socket port #
307
 mov  eax, 3
307
 mov  eax, 3
308
 mcall
308
 mcall
309
 mov  ecx, eax
309
 mov  ecx, eax
310
 shr  ecx, 8	; Set up the local port # with a random #
310
 shr  ecx, 8	; Set up the local port # with a random #
311
   
311
   
312
   ; open socket
312
   ; open socket
313
 mov  eax, 53
313
 mov  eax, 53
314
 mov  ebx, 0
314
 mov  ebx, 0
315
 mov  edx, 69	 ; remote port
315
 mov  edx, 69	 ; remote port
316
 mov  esi, [tftp_IP]  ; remote IP ( in intenet format )
316
 mov  esi, [tftp_IP]  ; remote IP ( in intenet format )
317
 mcall
317
 mcall
318
   
318
   
319
 mov  [socketNum], eax
319
 mov  [socketNum], eax
320
   
320
   
321
 ; make sure there is no data in the socket - there shouldn't be..
321
 ; make sure there is no data in the socket - there shouldn't be..
322
   
322
   
323
cfr001:
323
cfr001:
324
 mov  eax, 53
324
 mov  eax, 53
325
 mov  ebx, 3
325
 mov  ebx, 3
326
 mov  ecx, [socketNum]
326
 mov  ecx, [socketNum]
327
 mcall    ; read byte
327
 mcall    ; read byte
328
   
328
   
329
 mov  eax, 53
329
 mov  eax, 53
330
 mov  ebx, 2
330
 mov  ebx, 2
331
 mov  ecx, [socketNum]
331
 mov  ecx, [socketNum]
332
 mcall    ; any more data?
332
 mcall    ; any more data?
333
   
333
   
334
 cmp  eax, 0
334
 cmp  eax, 0
335
 jne  cfr001	; yes, so get it
335
 jne  cfr001	; yes, so get it
336
   
336
   
337
 ; Now, request the file
337
 ; Now, request the file
338
 mov  eax, 53
338
 mov  eax, 53
339
 mov  ebx, 4
339
 mov  ebx, 4
340
 mov  ecx, [socketNum]
340
 mov  ecx, [socketNum]
341
 mov  edx, [tftp_len]
341
 mov  edx, [tftp_len]
342
 mov  esi, tftp_filename
342
 mov  esi, tftp_filename
343
 mcall
343
 mcall
344
   
344
   
345
cfr002:
345
cfr002:
346
   
346
   
347
    mov  eax,23 		; wait here for event
347
    mov  eax,23 		; wait here for event
348
    mov  ebx,1			; Time out after 10ms
348
    mov  ebx,1			; Time out after 10ms
349
    mcall
349
    mcall
350
   
350
   
351
    cmp  eax,1			; redraw request ?
351
    cmp  eax,1			; redraw request ?
352
    je	 cfr003
352
    je	 cfr003
353
    cmp  eax,2			; key in buffer ?
353
    cmp  eax,2			; key in buffer ?
354
    je	 cfr004
354
    je	 cfr004
355
    cmp  eax,3			; button in buffer ?
355
    cmp  eax,3			; button in buffer ?
356
    je	 cfr005
356
    je	 cfr005
357
   
357
   
358
    ; Any data to fetch?
358
    ; Any data to fetch?
359
 mov  eax, 53
359
 mov  eax, 53
360
 mov  ebx, 2
360
 mov  ebx, 2
361
 mov  ecx, [socketNum]
361
 mov  ecx, [socketNum]
362
 mcall
362
 mcall
363
   
363
   
364
 cmp  eax, 0
364
 cmp  eax, 0
365
 je  cfr002
365
 je  cfr002
366
   
366
   
367
 push eax     ; eax holds # chars
367
 push eax     ; eax holds # chars
368
   
368
   
369
 ; Update the text on the display - once
369
 ; Update the text on the display - once
370
 mov  eax, [prompt]
370
 mov  eax, [prompt]
371
 cmp  eax, p3
371
 cmp  eax, p3
372
 je  cfr008
372
 je  cfr008
373
 mov   dword [prompt], p3
373
 mov   dword [prompt], p3
374
 mov  dword [promptlen], p3len - p3
374
 mov  dword [promptlen], p3len - p3
375
 call  draw_window	      ;
375
 call  draw_window	      ;
376
   
376
   
377
cfr008:
377
cfr008:
378
 ; we have data - this will be a tftp frame
378
 ; we have data - this will be a tftp frame
379
   
379
   
380
 ; read first two bytes - opcode
380
 ; read first two bytes - opcode
381
 mov  eax, 53
381
 mov  eax, 53
382
 mov  ebx, 3
382
 mov  ebx, 3
383
 mov  ecx, [socketNum]
383
 mov  ecx, [socketNum]
384
 mcall   ; read byte
384
 mcall   ; read byte
385
   
385
   
386
 mov  eax, 53
386
 mov  eax, 53
387
 mov  ebx, 3
387
 mov  ebx, 3
388
 mov  ecx, [socketNum]
388
 mov  ecx, [socketNum]
389
 mcall   ; read byte
389
 mcall   ; read byte
390
   
390
   
391
 pop  eax
391
 pop  eax
392
 ; bl holds tftp opcode. Can only be 3 (data) or 5 ( error )
392
 ; bl holds tftp opcode. Can only be 3 (data) or 5 ( error )
393
   
393
   
394
 cmp  bl, 3
394
 cmp  bl, 3
395
 jne  cfrerr
395
 jne  cfrerr
396
   
396
   
397
 push eax
397
 push eax
398
   
398
   
399
 ; do data stuff. Read block #. Read data. Send Ack.
399
 ; do data stuff. Read block #. Read data. Send Ack.
400
 mov  eax, 53
400
 mov  eax, 53
401
 mov  ebx, 3
401
 mov  ebx, 3
402
 mov  ecx, [socketNum]
402
 mov  ecx, [socketNum]
403
 mcall   ; read byte
403
 mcall   ; read byte
404
   
404
   
405
 mov  [blockNumber], bl
405
 mov  [blockNumber], bl
406
   
406
   
407
 mov  eax, 53
407
 mov  eax, 53
408
 mov  ebx, 3
408
 mov  ebx, 3
409
 mov  ecx, [socketNum]
409
 mov  ecx, [socketNum]
410
 mcall   ; read byte
410
 mcall   ; read byte
411
   
411
   
412
 mov  [blockNumber+1], bl
412
 mov  [blockNumber+1], bl
413
   
413
   
414
cfr007:
414
cfr007:
415
 mov  eax, 53
415
 mov  eax, 53
416
 mov  ebx, 3
416
 mov  ebx, 3
417
 mov  ecx, [socketNum]
417
 mov  ecx, [socketNum]
418
 mcall   ; read byte
418
 mcall   ; read byte
419
   
419
   
420
 mov  esi, [fileposition]
420
 mov  esi, [fileposition]
421
 mov  [esi], bl
421
 mov  [esi], bl
422
 mov  [esi+1],bl
422
 mov  [esi+1],bl
423
 add  dword [fileposition],2
423
 add  dword [fileposition],2
424
   
424
   
425
 mov  eax, 53
425
 mov  eax, 53
426
 mov  ebx, 2
426
 mov  ebx, 2
427
 mov  ecx, [socketNum]
427
 mov  ecx, [socketNum]
428
 mcall   ; any more data?
428
 mcall   ; any more data?
429
   
429
   
430
 cmp  eax, 0
430
 cmp  eax, 0
431
 jne  cfr007  ; yes, so get it
431
 jne  cfr007  ; yes, so get it
432
   
432
   
433
 cmp  [fileposition],0x20000+0xffff
433
 cmp  [fileposition],0x20000+0xffff
434
 jb   get_more_stream
434
 jb   get_more_stream
435
   
435
   
436
wait_more:
436
wait_more:
437
   
437
   
438
 mov  eax,5    ; wait for correct timer position
438
 mov  eax,5    ; wait for correct timer position
439
	       ; to trigger new play block
439
	       ; to trigger new play block
440
 mov  ebx,1
440
 mov  ebx,1
441
 mcall
441
 mcall
442
   
442
   
443
 mov  eax,26
443
 mov  eax,26
444
 mov  ebx,9
444
 mov  ebx,9
445
 mcall
445
 mcall
446
   
446
   
447
 cmp  eax,[wait_for]
447
 cmp  eax,[wait_for]
448
 jb   wait_more
448
 jb   wait_more
449
   
449
   
450
 add  eax,[delay]
450
 add  eax,[delay]
451
 mov  [wait_for],eax
451
 mov  [wait_for],eax
452
   
452
   
453
 mov  esi,0x20000
453
 mov  esi,0x20000
454
 mov  edi,0x10000
454
 mov  edi,0x10000
455
 mov  ecx,65536
455
 mov  ecx,65536
456
 cld
456
 cld
457
 rep  movsb
457
 rep  movsb
458
   
458
   
459
 mov  eax,55
459
 mov  eax,55
460
 mov  ebx,0
460
 mov  ebx,0
461
 mov  ecx,0x10000
461
 mov  ecx,0x10000
462
 mcall
462
 mcall
463
   
463
   
464
 mov  eax,55
464
 mov  eax,55
465
 mov  ebx,1
465
 mov  ebx,1
466
 mcall
466
 mcall
467
   
467
   
468
 mov  [fileposition],0x20000
468
 mov  [fileposition],0x20000
469
   
469
   
470
get_more_stream:
470
get_more_stream:
471
   
471
   
472
 ; write the block number into the ack
472
 ; write the block number into the ack
473
 mov  al, [blockNumber]
473
 mov  al, [blockNumber]
474
 mov  [ack + 2], al
474
 mov  [ack + 2], al
475
   
475
   
476
 mov  al, [blockNumber+1]
476
 mov  al, [blockNumber+1]
477
 mov  [ack + 3], al
477
 mov  [ack + 3], al
478
   
478
   
479
 ; send an 'ack'
479
 ; send an 'ack'
480
 mov  eax, 53
480
 mov  eax, 53
481
 mov  ebx, 4
481
 mov  ebx, 4
482
 mov  ecx, [socketNum]
482
 mov  ecx, [socketNum]
483
 mov  edx, ackLen - ack
483
 mov  edx, ackLen - ack
484
 mov  esi, ack
484
 mov  esi, ack
485
 mcall
485
 mcall
486
   
486
   
487
 ; If # of chars in the frame is less that 516,
487
 ; If # of chars in the frame is less that 516,
488
 ; this frame is the last
488
 ; this frame is the last
489
 pop  eax
489
 pop  eax
490
 cmp  eax, 516
490
 cmp  eax, 516
491
 je  cfr002
491
 je  cfr002
492
   
492
   
493
 ; Write the file
493
 ; Write the file
494
 mov  eax, 33
494
 mov  eax, 33
495
 mov  ebx, source
495
 mov  ebx, source
496
 mov  edx, [filesize]
496
 mov  edx, [filesize]
497
 mov  ecx, I_END + 512
497
 mov  ecx, I_END + 512
498
 mov  esi, 0
498
 mov  esi, 0
499
 mcall
499
 mcall
500
   
500
   
501
 jmp  cfrexit
501
 jmp  cfrexit
502
   
502
   
503
cfrerr:
503
cfrerr:
504
 ; simple implementation on error - just read all data, and return
504
 ; simple implementation on error - just read all data, and return
505
 mov  eax, 53
505
 mov  eax, 53
506
 mov  ebx, 3
506
 mov  ebx, 3
507
 mov  ecx, [socketNum]
507
 mov  ecx, [socketNum]
508
    mcall	  ; read byte
508
    mcall	  ; read byte
509
   
509
   
510
 mov  eax, 53
510
 mov  eax, 53
511
 mov  ebx, 2
511
 mov  ebx, 2
512
 mov  ecx, [socketNum]
512
 mov  ecx, [socketNum]
513
    mcall	  ; any more data?
513
    mcall	  ; any more data?
514
   
514
   
515
 cmp  eax, 0
515
 cmp  eax, 0
516
 jne  cfrerr	; yes, so get it
516
 jne  cfrerr	; yes, so get it
517
   
517
   
518
 jmp  cfr006	; close socket and close app
518
 jmp  cfr006	; close socket and close app
519
   
519
   
520
cfr003: 			; redraw request
520
cfr003: 			; redraw request
521
    call draw_window
521
    call draw_window
522
    jmp  cfr002
522
    jmp  cfr002
523
   
523
   
524
cfr004: 			; key pressed
524
cfr004: 			; key pressed
525
    mov  eax,2			; just read it and ignore
525
    mov  eax,2			; just read it and ignore
526
    mcall
526
    mcall
527
    jmp  cfr002
527
    jmp  cfr002
528
   
528
   
529
cfr005: 		       ; button
529
cfr005: 		       ; button
530
    mov  eax,17 		; get id
530
    mov  eax,17 		; get id
531
    mcall
531
    mcall
532
   
532
   
533
    cmp  ah,1			; button id=1 ?
533
    cmp  ah,1			; button id=1 ?
534
    jne  cfr002     ; If not, ignore.
534
    jne  cfr002     ; If not, ignore.
535
   
535
   
536
cfr006:
536
cfr006:
537
    ; close socket
537
    ; close socket
538
 mov  eax, 53
538
 mov  eax, 53
539
 mov  ebx, 1
539
 mov  ebx, 1
540
 mov  ecx, [socketNum]
540
 mov  ecx, [socketNum]
541
    mcall
541
    mcall
542
   
542
   
543
 mov  [socketNum], dword 0
543
 mov  [socketNum], dword 0
544
   
544
   
545
    mov  eax,-1 		; close this program
545
    mov  eax,-1 		; close this program
546
    mcall
546
    mcall
547
   
547
   
548
    jmp $
548
    jmp $
549
   
549
   
550
cfrexit:
550
cfrexit:
551
    ; close socket
551
    ; close socket
552
 mov  eax, 53
552
 mov  eax, 53
553
 mov  ebx, 1
553
 mov  ebx, 1
554
 mov  ecx, [socketNum]
554
 mov  ecx, [socketNum]
555
    mcall
555
    mcall
556
   
556
   
557
 mov  [socketNum], dword 0
557
 mov  [socketNum], dword 0
558
   
558
   
559
    mov   dword [prompt], p4
559
    mov   dword [prompt], p4
560
    mov  dword [promptlen], p4len - p4
560
    mov  dword [promptlen], p4len - p4
561
    call  draw_window		 ;
561
    call  draw_window		 ;
562
   
562
   
563
 ret
563
 ret
564
   
564
   
565
   
565
   
566
   
566
   
567
   
567
   
568
;   *********************************************
568
;   *********************************************
569
;   *******  WINDOW DEFINITIONS AND DRAW ********
569
;   *******  WINDOW DEFINITIONS AND DRAW ********
570
;   *********************************************
570
;   *********************************************
571
   
571
   
572
   
572
   
573
draw_window:
573
draw_window:
574
   
574
   
575
    mov  eax,12 		   ; function 12:tell os about windowdraw
575
    mov  eax,12 		   ; function 12:tell os about windowdraw
576
    mov  ebx,1			   ; 1, start of draw
576
    mov  ebx,1			   ; 1, start of draw
577
    mcall
577
    mcall
578
   
578
   
579
				   ; DRAW WINDOW
579
				   ; DRAW WINDOW
580
    mov  eax,0			   ; function 0 : define and draw window
580
    mov  eax,0			   ; function 0 : define and draw window
581
    mov  ebx,100*65536+230	   ; [x start] *65536 + [x size]
581
    mov  ebx,100*65536+230	   ; [x start] *65536 + [x size]
582
    mov  ecx,100*65536+170	   ; [y start] *65536 + [y size]
582
    mov  ecx,100*65536+170	   ; [y start] *65536 + [y size]
583
    mov  edx,0x13224466 	   ; color of work area RRGGBB
583
    mov  edx,0x14224466 	   ; color of work area RRGGBB
584
    mov  edi,title
584
    mov  edi,title
585
    mcall
585
    mcall
586
   
586
   
587
    mov  eax,8		    ; DELETE BUTTON
587
    mov  eax,8		    ; DELETE BUTTON
588
    mov  ebx,20*65536+190
588
    mov  ebx,20*65536+190
589
    mov  ecx,111*65536+15
589
    mov  ecx,111*65536+15
590
    mov  edx,2
590
    mov  edx,2
591
    mov  esi,0x557799
591
    mov  esi,0x557799
592
    mcall
592
    mcall
593
   
593
   
594
    mov  ebx,200*65536+10
594
    mov  ebx,200*65536+10
595
    mov  ecx,34*65536+10
595
    mov  ecx,34*65536+10
596
    mov  edx,4
596
    mov  edx,4
597
    mcall
597
    mcall
598
   
598
   
599
    mov  ecx,50*65536+10
599
    mov  ecx,50*65536+10
600
    mov  edx,5
600
    mov  edx,5
601
    mcall
601
    mcall
602
   
602
   
603
   
603
   
604
 ; Copy the file name to the screen buffer
604
 ; Copy the file name to the screen buffer
605
 ; file name is same length as IP address, to
605
 ; file name is same length as IP address, to
606
 ; make the math easier later.
606
 ; make the math easier later.
607
    cld
607
    cld
608
    mov  esi,source
608
    mov  esi,source
609
    mov  edi,text+13
609
    mov  edi,text+13
610
    mov  ecx,15
610
    mov  ecx,15
611
    rep  movsb
611
    rep  movsb
612
   
612
   
613
   
613
   
614
 ; copy the IP address to the screen buffer
614
 ; copy the IP address to the screen buffer
615
    mov  esi,destination
615
    mov  esi,destination
616
    mov  edi,text+40+13
616
    mov  edi,text+40+13
617
    mov  ecx,15
617
    mov  ecx,15
618
    rep  movsb
618
    rep  movsb
619
   
619
   
620
  ; copy the prompt to the screen buffer
620
  ; copy the prompt to the screen buffer
621
    mov  esi,[prompt]
621
    mov  esi,[prompt]
622
    mov  edi,text+280
622
    mov  edi,text+280
623
    mov  ecx,[promptlen]
623
    mov  ecx,[promptlen]
624
    rep  movsb
624
    rep  movsb
625
   
625
   
626
    ; Re-draw the screen text
626
    ; Re-draw the screen text
627
    cld
627
    cld
628
    mov  eax,4
628
    mov  eax,4
629
    mov  ebx,25*65536+35	   ; draw info text with function 4
629
    mov  ebx,25*65536+35	   ; draw info text with function 4
630
    mov  ecx,0xffffff
630
    mov  ecx,0xffffff
631
    mov  edx,text
631
    mov  edx,text
632
    mov  esi,40
632
    mov  esi,40
633
  newline:
633
  newline:
634
    mcall
634
    mcall
635
    add  ebx,16
635
    add  ebx,16
636
    add  edx,40
636
    add  edx,40
637
    cmp  [edx],byte 'x'
637
    cmp  [edx],byte 'x'
638
    jnz  newline
638
    jnz  newline
639
   
639
   
640
   
640
   
641
    mov  eax,12 		   ; function 12:tell os about windowdraw
641
    mov  eax,12 		   ; function 12:tell os about windowdraw
642
    mov  ebx,2			   ; 2, end of draw
642
    mov  ebx,2			   ; 2, end of draw
643
    mcall
643
    mcall
644
   
644
   
645
    ret
645
    ret
646
   
646
   
647
   
647
   
648
; DATA AREA
648
; DATA AREA
649
   
649
   
650
source	     db  'HEAT8M22.WAV   '
650
source	     db  'HEAT8M22.WAV   '
651
destination  db  '192.168.1.24   '
651
destination  db  '192.168.1.24   '
652
   
652
   
653
   
653
   
654
tftp_filename:	times 15 + 9 db 0
654
tftp_filename:	times 15 + 9 db 0
655
tftp_IP:   dd 0
655
tftp_IP:   dd 0
656
tftp_len:   dd 0
656
tftp_len:   dd 0
657
   
657
   
658
addr  dd  0x0
658
addr  dd  0x0
659
ya    dd  0x0
659
ya    dd  0x0
660
   
660
   
661
fileposition dd 0 ; Points to the current point in the file
661
fileposition dd 0 ; Points to the current point in the file
662
filesize  dd 0 ; The number of bytes written / left to write
662
filesize  dd 0 ; The number of bytes written / left to write
663
fileblocksize dw 0 ; The number of bytes to send in this frame
663
fileblocksize dw 0 ; The number of bytes to send in this frame
664
   
664
   
665
text:
665
text:
666
    db 'SOURCE FILE: xxxxxxxxxxxxxxx            '
666
    db 'SOURCE FILE: xxxxxxxxxxxxxxx            '
667
    db 'HOST IP ADD: xxx.xxx.xxx.xxx            '
667
    db 'HOST IP ADD: xxx.xxx.xxx.xxx            '
668
    db '                                        '
668
    db '                                        '
669
    db 'WAVE FORMAT: 8 BIT,MONO,22050HZ         '
669
    db 'WAVE FORMAT: 8 BIT,MONO,22050HZ         '
670
    db '                                        '
670
    db '                                        '
671
    db '     SERVER -> PLAY FILE                '
671
    db '     SERVER -> PLAY FILE                '
672
    db '                                        '
672
    db '                                        '
673
    db '                                        '
673
    db '                                        '
674
    db 'x' ; <- END MARKER, DONT DELETE
674
    db 'x' ; <- END MARKER, DONT DELETE
675
   
675
   
676
   
676
   
677
title	db   'TFTP Wave Player',0   
677
title	db   'TFTP Wave Player',0   
678
   
678
   
679
prompt: dd 0
679
prompt: dd 0
680
promptlen: dd 0
680
promptlen: dd 0
681
   
681
   
682
   
682
   
683
p1:  db 'Waiting for Command '
683
p1:  db 'Waiting for Command '
684
p1len:
684
p1len:
685
   
685
   
686
p9:  db 'Define SB with setup'
686
p9:  db 'Define SB with setup'
687
p9len:
687
p9len:
688
   
688
   
689
p2:  db 'Sending File        '
689
p2:  db 'Sending File        '
690
p2len:
690
p2len:
691
   
691
   
692
p3:  db 'Playing File        '
692
p3:  db 'Playing File        '
693
p3len:
693
p3len:
694
   
694
   
695
p4:  db 'Complete            '
695
p4:  db 'Complete            '
696
p4len:
696
p4len:
697
   
697
   
698
p5:  db 'Contacting Host...  '
698
p5:  db 'Contacting Host...  '
699
p5len:
699
p5len:
700
   
700
   
701
p6:  db 'File not found.     '
701
p6:  db 'File not found.     '
702
p6len:
702
p6len:
703
   
703
   
704
ack:
704
ack:
705
 db 00,04,0,1
705
 db 00,04,0,1
706
ackLen:
706
ackLen:
707
   
707
   
708
socketNum:
708
socketNum:
709
 dd 0
709
 dd 0
710
   
710
   
711
blockNumber:
711
blockNumber:
712
 dw 0
712
 dw 0
713
   
713
   
714
; This must be the last part of the file, because the blockBuffer
714
; This must be the last part of the file, because the blockBuffer
715
; continues at I_END.
715
; continues at I_END.
716
blockBuffer:
716
blockBuffer:
717
 db 00, 03, 00, 01
717
 db 00, 03, 00, 01
718
I_END:
718
I_END: