Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; |
2 | ; Remote processing example (local node) |
||
3 | ; |
||
4 | ; Compile with FASM for Menuet |
||
5 | ; |
||
6 | |||
7 | |||
8 | use32 |
||
485 | heavyiron | 9 | org 0x0 |
10 | db 'MENUET01' ; header |
||
11 | dd 0x01 ; header version |
||
12 | dd START ; entry point |
||
13 | dd I_END ; image size |
||
14 | dd I_END+0x10000 ; required memory |
||
15 | dd I_END+0x10000 ; esp |
||
16 | dd 0x0 , 0x0 ; I_Param , I_Path |
||
17 | |||
31 | halyavin | 18 | |
19 | include 'lang.inc' |
||
485 | heavyiron | 20 | include '..\..\..\macros.inc' |
31 | halyavin | 21 | |
22 | START: ; start of execution |
||
23 | |||
24 | mov eax,53 ; open socket |
||
25 | mov ebx,0 |
||
26 | mov ecx,0x2000 ; local port |
||
27 | mov edx,0x3000 ; remote port |
||
28 | mov esi,dword [host_ip] ; node IP |
||
485 | heavyiron | 29 | mcall |
31 | halyavin | 30 | |
31 | mov [socketNum], eax |
||
485 | heavyiron | 32 | |
33 | red: |
||
31 | halyavin | 34 | call draw_window ; at first, draw the window |
35 | |||
36 | still: |
||
37 | |||
38 | mov eax,23 ; wait here for event |
||
39 | mov ebx,1 |
||
485 | heavyiron | 40 | mcall |
31 | halyavin | 41 | |
42 | cmp eax,1 ; redraw request ? |
||
43 | jz red |
||
44 | cmp eax,2 ; key in buffer ? |
||
45 | jz key |
||
46 | cmp eax,3 ; button in buffer ? |
||
47 | jz button |
||
48 | |||
49 | mov eax, 53 ; get data |
||
50 | mov ebx, 2 |
||
51 | mov ecx, [socketNum] |
||
485 | heavyiron | 52 | mcall |
31 | halyavin | 53 | cmp eax, 0 |
54 | jne read |
||
55 | |||
56 | jmp still |
||
57 | |||
58 | key: |
||
59 | mov eax,2 |
||
485 | heavyiron | 60 | mcall |
31 | halyavin | 61 | jmp still |
62 | |||
63 | button: |
||
64 | mov eax,17 |
||
485 | heavyiron | 65 | mcall |
31 | halyavin | 66 | |
67 | cmp ah,1 ; button id=1 ? |
||
68 | jnz noclose |
||
69 | mov eax, 53 |
||
70 | mov ebx, 1 |
||
71 | mov ecx, [socketNum] |
||
485 | heavyiron | 72 | mcall |
31 | halyavin | 73 | mov eax,-1 |
485 | heavyiron | 74 | mcall |
31 | halyavin | 75 | noclose: |
76 | |||
77 | cmp ah,2 ; SEND CODE ? |
||
78 | je send_xcode |
||
79 | |||
80 | cmp ah,3 ; LEFT COORDINATES ? |
||
81 | jne no_left |
||
82 | mov [picture_position],0 |
||
83 | mov dword [send_data+15],dword STARTX |
||
84 | mov dword [send_data+19],dword 4 |
||
85 | mov esi,send_data |
||
86 | mov edi,I_END |
||
87 | mov ecx,23 |
||
88 | cld |
||
89 | rep movsb |
||
90 | mov [I_END+23],dword -20 |
||
91 | mov eax,53 |
||
92 | mov ebx,4 |
||
93 | mov ecx,[socketNum] |
||
94 | mov edx,23 + 4 |
||
95 | mov esi,I_END |
||
485 | heavyiron | 96 | mcall |
31 | halyavin | 97 | jmp still |
98 | no_left: |
||
99 | |||
100 | cmp ah,4 ; RIGHT COORDINATES ? |
||
101 | jne no_right |
||
102 | mov [picture_position],128 |
||
103 | mov dword [send_data+15],dword STARTX |
||
104 | mov dword [send_data+19],dword 4 |
||
105 | mov esi,send_data |
||
106 | mov edi,I_END |
||
107 | mov ecx,23 |
||
108 | cld |
||
109 | rep movsb |
||
110 | mov [I_END+23],dword -20 + 128 |
||
111 | mov eax,53 |
||
112 | mov ebx,4 |
||
113 | mov ecx,[socketNum] |
||
114 | mov edx,23 + 4 |
||
115 | mov esi,I_END |
||
485 | heavyiron | 116 | mcall |
31 | halyavin | 117 | jmp still |
118 | no_right: |
||
119 | |||
120 | cmp ah,5 ; SEND EXECUTE ? |
||
121 | je send_execute |
||
122 | |||
123 | jmp still |
||
124 | |||
125 | |||
126 | xx dd 0 |
||
127 | yy dd 0 |
||
128 | |||
129 | |||
130 | |||
131 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
132 | ;; ;; |
||
133 | ;; SEND CODE TO REMOTE ;; |
||
134 | ;; ;; |
||
135 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
136 | |||
137 | send_xcode: |
||
138 | |||
139 | mov dword [send_data+15],dword 0x80000 |
||
140 | mov dword [send_data+19],dword remote_code_end - remote_code_start |
||
141 | |||
142 | mov esi,send_data ; header |
||
143 | mov edi,I_END |
||
144 | mov ecx,23 |
||
145 | cld |
||
146 | rep movsb |
||
147 | |||
148 | mov esi,remote_code ; remote_code_start ; data |
||
149 | mov edi,I_END+23 |
||
150 | mov ecx,remote_code_end - remote_code_start |
||
151 | cld |
||
152 | rep movsb |
||
153 | |||
154 | mov eax,53 ; SEND CODE TO REMOTE |
||
155 | mov ebx,4 |
||
156 | mov ecx,[socketNum] |
||
157 | mov edx,23 + remote_code_end - remote_code_start |
||
158 | mov esi,I_END |
||
485 | heavyiron | 159 | mcall |
31 | halyavin | 160 | |
161 | jmp still |
||
162 | |||
163 | |||
164 | send_execute: |
||
165 | |||
166 | mov dword [execute+15],dword draw_fractal |
||
167 | |||
168 | mov eax,53 ; START EXECUTE AT REMOTE |
||
169 | mov ebx,4 |
||
170 | mov ecx,[socketNum] |
||
171 | mov edx,19 |
||
172 | mov esi,execute |
||
485 | heavyiron | 173 | mcall |
31 | halyavin | 174 | |
175 | mov edi,3 |
||
176 | |||
177 | jmp still |
||
178 | |||
179 | |||
180 | |||
181 | ;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
182 | ;; ;; |
||
183 | ;; READ ;; |
||
184 | ;; ;; |
||
185 | ;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
186 | |||
187 | |||
188 | read: |
||
189 | |||
190 | |||
191 | cfr007: |
||
192 | |||
193 | mov eax, 53 |
||
194 | mov ebx, 3 |
||
195 | mov ecx, [socketNum] |
||
485 | heavyiron | 196 | mcall ; read byte |
31 | halyavin | 197 | |
198 | shl edx,8 |
||
199 | mov dl,bl |
||
200 | |||
201 | dec edi |
||
202 | jnz cok |
||
203 | |||
204 | mov edi,3 |
||
205 | |||
206 | and edx,0xffffff |
||
207 | mov eax,1 |
||
208 | mov ebx,[xx] |
||
209 | mov ecx,[yy] |
||
210 | add ebx,15 |
||
211 | add ecx,35 |
||
212 | add ebx,[picture_position] |
||
485 | heavyiron | 213 | mcall |
31 | halyavin | 214 | |
215 | inc [xx] |
||
216 | cmp [xx],dword 128 |
||
217 | jb cok |
||
218 | mov [xx],0 |
||
219 | |||
220 | inc [yy] |
||
221 | cmp [yy],dword 128 |
||
222 | jb cok |
||
223 | mov [yy],0 |
||
224 | |||
225 | cok: |
||
226 | |||
227 | mov eax, 53 |
||
228 | mov ebx, 2 |
||
229 | mov ecx, [socketNum] |
||
485 | heavyiron | 230 | mcall ; any more data? |
31 | halyavin | 231 | |
232 | cmp eax, 0 |
||
233 | jne cfr007 ; yes, so get it |
||
234 | |||
235 | jmp still |
||
236 | |||
237 | |||
238 | |||
239 | |||
240 | ; ********************************************* |
||
241 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
242 | ; ********************************************* |
||
243 | |||
244 | |||
245 | draw_window: |
||
246 | |||
247 | mov eax,12 ; function 12:tell os about windowdraw |
||
248 | mov ebx,1 ; 1, start of draw |
||
485 | heavyiron | 249 | mcall |
31 | halyavin | 250 | |
251 | ; DRAW WINDOW |
||
252 | mov eax,0 ; function 0 : define and draw window |
||
253 | mov ebx,100*65536+286 ; [x start] *65536 + [x size] |
||
485 | heavyiron | 254 | mov ecx,60*65536+330 ; [y start] *65536 + [y size] |
551 | spraid | 255 | mov edx,0x04ffffff ; color of work area RRGGBB |
485 | heavyiron | 256 | mov edi,title ; WINDOW LABEL |
257 | mcall |
||
31 | halyavin | 258 | |
485 | heavyiron | 259 | |
31 | halyavin | 260 | mov eax,8 ; SEND CODE |
261 | mov ebx,60*65536+160 |
||
262 | mov ecx,181*65536+13 |
||
263 | mov edx,2 |
||
264 | mov esi,0x667788 |
||
485 | heavyiron | 265 | mcall |
31 | halyavin | 266 | |
485 | heavyiron | 267 | ;mov eax,8 ; LEFT |
31 | halyavin | 268 | mov ebx,60*65536+75 |
269 | mov ecx,197*65536+13 |
||
270 | mov edx,3 |
||
485 | heavyiron | 271 | mcall |
31 | halyavin | 272 | |
485 | heavyiron | 273 | ;mov eax,8 ; RIGHT |
31 | halyavin | 274 | mov ebx,148*65536+72 |
275 | mov ecx,197*65536+13 |
||
276 | mov edx,4 |
||
485 | heavyiron | 277 | mcall |
31 | halyavin | 278 | |
485 | heavyiron | 279 | ;mov eax,8 ; SEND EXECUTE |
31 | halyavin | 280 | mov ebx,60*65536+160 |
281 | mov ecx,213*65536+13 |
||
282 | mov edx,5 |
||
485 | heavyiron | 283 | mcall |
31 | halyavin | 284 | |
285 | |||
286 | cld |
||
485 | heavyiron | 287 | mov eax,4 |
31 | halyavin | 288 | mov ebx,25*65536+185 ; draw info text with function 4 |
289 | mov ecx,0x000000 |
||
290 | mov edx,text |
||
291 | mov esi,40 |
||
292 | newline: |
||
485 | heavyiron | 293 | mcall |
31 | halyavin | 294 | add ebx,16 |
295 | add edx,40 |
||
296 | cmp [edx],byte 'x' |
||
297 | jnz newline |
||
298 | |||
299 | mov eax,12 ; function 12:tell os about windowdraw |
||
300 | mov ebx,2 ; 2, end of draw |
||
485 | heavyiron | 301 | mcall |
31 | halyavin | 302 | |
303 | ret |
||
304 | |||
305 | |||
306 | ; DATA AREA |
||
307 | |||
308 | |||
309 | text: |
||
310 | db ' 1) SEND CODE ' |
||
311 | db ' 2) LEFT RIGHT ' |
||
312 | db " 3) SEND 'EXECUTE' " |
||
313 | db ' ' |
||
314 | db ' LOCAL : 192.168.1.26 ' |
||
315 | db ' REMOTE : 192.168.1.22 ' |
||
316 | db ' REMOTE CODE AT THE END OF THIS FILE ' |
||
485 | heavyiron | 317 | db 'x' ;<- END MARKER, DONT DELETE |
31 | halyavin | 318 | |
319 | |||
485 | heavyiron | 320 | title db 'CLUSTER LOCAL',0 |
31 | halyavin | 321 | |
322 | socketNum dd 0x0 |
||
323 | |||
324 | host_ip db 192,168,1,22 |
||
325 | |||
326 | picture_position dd 0x0 |
||
327 | |||
328 | send_data db 'MenuetRemote00' ; 00 header ; -> remote port 0x3000 |
||
329 | db 1 ; 14 send |
||
330 | dd 0x0 ; 15 position |
||
331 | dd 0x0 ; 19 size |
||
332 | ; 23 |
||
333 | |||
334 | execute db 'MenuetRemote00' ; 00 header ; -> remote port 0x3000 |
||
335 | db 2 ; 14 execute |
||
336 | dd 0x0 ; 15 position |
||
337 | ; 19 |
||
338 | |||
339 | |||
340 | |||
341 | |||
342 | |||
343 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
344 | ;; ;; |
||
345 | ;; REMOTE CODE ;; |
||
346 | ;; ;; |
||
347 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
348 | |||
349 | |||
350 | |||
351 | remote_code: |
||
352 | |||
353 | |||
354 | org 0x80000 |
||
355 | |||
356 | remote_code_start: |
||
357 | |||
358 | |||
359 | PIXWIDTH equ 129 |
||
360 | PIXHEIGHT equ 129 |
||
361 | ZOOMLIMIT equ 13 |
||
362 | DELTA equ 200 |
||
363 | THRESHOLD equ 7 |
||
364 | STARTSCALE equ 6 |
||
365 | CHAR_COLOR equ 0fh |
||
366 | |||
367 | STARTX dd -20 |
||
368 | STARTY dd 10 |
||
369 | scaleaddy dd 60 |
||
370 | scaleaddx dd 100 |
||
371 | |||
372 | |||
373 | |||
374 | draw_fractal: |
||
375 | |||
376 | pusha |
||
377 | |||
378 | movzx ebp,word [STARTX] |
||
379 | movzx edi,word [STARTY] |
||
380 | mov cx, PIXHEIGHT ; height of screen in pixels |
||
381 | |||
382 | sub di,cx ; adjust our Y offset |
||
383 | @@CalcRow: |
||
384 | |||
385 | push cx |
||
386 | mov cx, PIXWIDTH -1 ; width of screen in pixels |
||
387 | |||
388 | sub bp,cx ; |
||
389 | @@CalcPixel: |
||
390 | push cx ; save the column counter on stack |
||
391 | xor cx, cx ; clear out color loop counter |
||
392 | xor bx, bx ; zero i coefficient |
||
393 | xor dx, dx ; zero j coefficient |
||
394 | @@CycleColors: |
||
395 | push dx ; save j value for later |
||
396 | mov ax, bx ; ax = i |
||
397 | sub ax, dx ; ax = i - j |
||
398 | add dx, bx ; dx = i + j |
||
399 | stc ; one additional shift, please |
||
400 | call Shifty ; ax = ((i+j)*(i-j)) shifted right |
||
401 | pop dx ; retrieve our saved value for j |
||
402 | add ax,bp ; account for base offset... |
||
403 | cmp ah,THRESHOLD ; Q: is i > THRESHOLD * 256? |
||
404 | xchg bx,ax ; now swap new i with old i |
||
405 | jg @@draw ; Y: draw this pixel |
||
406 | clc ; no additional shifts here, please |
||
407 | call Shifty ; now dx:ax = old i * j |
||
408 | xchg dx,ax ; |
||
409 | add dx,di ; account for base offset... |
||
410 | inc cl ; increment color |
||
411 | jnz @@CycleColors ; keep going until we're done |
||
412 | @@draw: |
||
413 | xchg ax, cx ; mov color into al |
||
414 | pop cx ; retrieve our column counter |
||
415 | pop dx ; fetch row (column already in cx) |
||
416 | push dx ; must leave a copy on the stack |
||
417 | xor bx,bx ; write to video page zero |
||
418 | |||
419 | call store_pixel |
||
420 | |||
421 | inc bp |
||
422 | loop @@CalcPixel |
||
423 | inc di |
||
424 | pop cx |
||
425 | loop @@CalcRow |
||
426 | |||
427 | call return_data |
||
428 | |||
429 | popa |
||
430 | |||
431 | ret |
||
432 | |||
433 | |||
434 | Shifty: |
||
435 | |||
436 | push cx |
||
437 | db 0b1h |
||
438 | scale db STARTSCALE |
||
439 | adc cl,0 |
||
440 | imul dx |
||
441 | |||
442 | xchg ax,dx |
||
443 | shl eax,16 |
||
444 | xchg ax,dx |
||
445 | shr eax,cl |
||
446 | |||
447 | pop cx |
||
448 | ret |
||
449 | |||
450 | |||
451 | pixel_pos: dd data_area |
||
452 | |||
453 | store_pixel: |
||
454 | |||
455 | pusha |
||
456 | |||
457 | mov ebx,[pixel_pos] |
||
458 | shl eax,3 |
||
459 | and eax,0xff |
||
460 | mov [ebx],eax |
||
461 | add dword [pixel_pos],dword 3 |
||
462 | |||
463 | popa |
||
464 | ret |
||
465 | |||
466 | |||
467 | return_data: |
||
468 | |||
469 | mov ecx,128 * 128/16 |
||
470 | mov esi,data_area |
||
471 | |||
472 | sd: |
||
473 | |||
474 | pusha |
||
475 | |||
476 | mov eax,53 ; use the socket provided by host |
||
477 | mov ebx,4 |
||
478 | mov ecx,[0] |
||
479 | mov edx,3*16 |
||
485 | heavyiron | 480 | mcall |
31 | halyavin | 481 | |
482 | mov eax,5 |
||
483 | mov ebx,1 |
||
485 | heavyiron | 484 | mcall |
31 | halyavin | 485 | |
486 | popa |
||
487 | |||
488 | add esi,3*16 |
||
489 | |||
490 | loop sd |
||
491 | |||
492 | ret |
||
493 | |||
494 | |||
495 | data_area: |
||
496 | |||
497 | remote_code_end: |
||
498 | |||
499 | |||
500 | I_END:-> |
||
501 |