Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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