Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;    VIRTUAL SCREEN 2
  3. ;    based on the original VSCREEN
  4. ;
  5. ;    Compile with FASM for Menuet
  6. ;'
  7.  
  8. use32
  9.  
  10.       org     0x0
  11.  
  12.       db      'MENUET01'      ; 8 byte id
  13.       dd      0x01            ; required os
  14.       dd      START           ; program start
  15.       dd      I_END           ; program image size
  16.       dd      0x600000        ; required amount of memory
  17.       dd      0xfff0
  18.       dd      0,0
  19.  
  20. scr   equ     0x20000
  21.  
  22. include 'lang.inc'
  23. include 'macros.inc'
  24.  
  25. START:                          ; start of execution
  26.  
  27.     mov  eax,14                 ; get screen size
  28.     int  0x40
  29.     push eax
  30.     and  eax,0x0000ffff
  31.     inc  eax
  32.     mov  [size_y],eax
  33.     pop  eax
  34.     shr  eax,16
  35.     inc  eax
  36.     mov  [size_x],eax
  37.  
  38.     mov  eax,[size_x]
  39.     shr  eax,2
  40.     mov  [cmp_ecx],eax
  41.  
  42.     mov  eax,[size_x]
  43.     xor  edx,edx
  44.     mov  ebx,3
  45.     mul  ebx
  46.     mov  [add_esi],eax
  47.  
  48.     mov  eax,[size_y]
  49.     shr  eax,2
  50.     mov  [cmp_edx],eax
  51.  
  52.     mov   eax,[size_y]
  53.     imul  eax,[size_x]
  54.     imul  eax,3
  55.     mov   [i_size],eax
  56.  
  57. red:
  58.     call draw_window            ; at first, draw the window
  59.  
  60. still:
  61.  
  62.     call draw_screen
  63.  
  64.     mov  eax,23                 ; wait here for event with timeout
  65.     mov  ebx,[delay]
  66.     int  0x40
  67.  
  68.     dec  eax                    ; redraw request ?
  69.     jz   red
  70.     dec  eax                    ; key in buffer ?
  71.     jz   key
  72.     dec  eax                    ; button in buffer ?
  73.     jz   button
  74.  
  75.     jmp  still
  76.  
  77.   key:                          ; key
  78.     mov  eax,2
  79.     int  0x40                   ; just read it and ignore
  80.     jmp  still
  81.  
  82.   button:                       ; button
  83.     mov  eax,17                 ; get id
  84.     int  0x40
  85.  
  86.     cmp  ah,1                   ; button id=1 ?
  87.     jnz  noclose
  88. exit:
  89.     or   eax,-1                 ; close this program
  90.     int  0x40
  91.   noclose:
  92.  
  93.     cmp  ah,2
  94.     jnz  still
  95.  
  96.     mov  eax,51
  97.     xor  ebx,ebx
  98.     inc  ebx
  99.     mov  ecx,thread_start
  100.     mov  edx,0xe000
  101.     int  0x40
  102.  
  103.     jmp  exit
  104.  
  105. thread_start:
  106.     mov  eax,5     ; wait for termination (1 sec.)
  107.     mov  ebx,100
  108.     int  0x40
  109.  
  110.     call save_screen
  111.     jmp  exit      ; exit thread
  112.  
  113. save_screen:
  114.  
  115.      pusha
  116.  
  117. ;     mov  eax,5
  118. ;     mov  ebx,500
  119. ;     int  0x40
  120.  
  121. ;     xor  ebx,ebx
  122. ;     mov  edi,0x10036    ;0x10000
  123. ;     mov  esi,edi        ;0x10000
  124. ;     add  esi,[i_size]
  125.  
  126. ;   ss1:
  127.  
  128. ;     mov  eax,35
  129. ;     int  0x40
  130.  
  131. ;     inc  ebx
  132.  
  133. ;     mov  [edi],eax
  134. ;     add  edi,3
  135.  
  136. ;     cmp  edi,esi
  137. ;     jb   ss1
  138.  
  139. ; 1) READ SCREEN
  140.      mov  edi,0x10036
  141.  
  142.      mov  eax,[size_y]
  143.      dec  eax
  144.      mov  [temp_y],eax
  145.  
  146.   ynew:
  147.  
  148.      xor  eax,eax
  149.      mov  [temp_x],eax
  150.  
  151.   xnew:
  152.  
  153.      mov  eax,[temp_x]
  154.      mov  ebx,[temp_y]
  155.      call read_pixel
  156.  
  157.      mov  [edi],eax
  158.      add  edi,3
  159.  
  160.      inc  [temp_x]
  161.  
  162.      mov  eax,[size_x]
  163.      cmp  [temp_x],eax
  164.      jb   xnew
  165.  
  166.      dec  [temp_y]
  167.  
  168.      cmp  [temp_y],0
  169.      jge  ynew
  170.  
  171. ; 2) BMP HEADER
  172.  
  173.      mov  [0x10000],word 'BM'     ; bmp signature
  174.      mov  eax,[i_size]
  175.      mov  [0x10000+34],eax        ; image size
  176.      mov  ebx,0x36
  177.      mov  [0x10000+10],ebx        ; headers size
  178.      add  eax,ebx
  179.      mov  [0x10000+2],eax         ; file size
  180.      mov  [0x10000+14],dword 0x28
  181.      mov  eax,[size_x]
  182.      mov  [0x10000+18],eax        ; x size
  183.      mov  eax,[size_y]
  184.      mov  [0x10000+22],eax        ; y size
  185.      mov  [0x10000+26],word 1
  186.      mov  [0x10000+28],word 0x18  ; bpp = 24 = 0x18
  187.  
  188. ; 3) SAVE FILE
  189.  
  190.      mov  eax,56
  191.      mov  ebx,filename
  192.      mov  edx,0x10000
  193.      mov  ecx,[i_size]
  194.      add  ecx,0x36
  195.      mov  esi,path
  196.      int  0x40
  197.  
  198.      popa
  199.      ret
  200.  
  201. filename  db  'SCREEN  BMP'
  202. path      db  0
  203.  
  204. read_pixel:
  205. pushad
  206.  
  207. mov esi,eax
  208. mov eax,[size_x]
  209. mul ebx
  210. add eax,esi
  211.  
  212. xchg eax,ebx
  213. mov eax,35
  214. int 0x40
  215. mov [esp+28],eax
  216.  
  217. popad
  218. ret
  219.  
  220. ;   *********************************************
  221. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  222. ;   *********************************************
  223.  
  224. draw_window:
  225.  
  226.     mov  eax,12                    ; function 12:tell os about windowdraw
  227.     mov  ebx,1                     ; 1, start of draw
  228.     int  0x40
  229.  
  230.                                    ; DRAW WINDOW
  231.     xor  eax,eax                   ; function 0 : define and draw window
  232.   movzx  ebx,word [size_x]
  233.     shr  ebx,2
  234.     add  ebx,100*65536+40
  235.  
  236.   movzx  ecx,word [size_y]
  237.     shr  ecx,2
  238.     add  ecx,100*65536+75
  239.  
  240.     mov  edx,0x027777dd  ;82       ; color of work area RRGGBB
  241.     mov  esi,0x807777dd            ; color of grab bar  RRGGBB,8->color gl
  242.     mov  edi,0x007777dd            ; color of frames    RRGGBB
  243.     int  0x40
  244.  
  245.                                    ; WINDOW LABEL
  246.     mov  eax,4                     ; function 4 : write text to window
  247.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  248.     mov  ecx,0x10ffffff            ; color of text RRGGBB
  249.     mov  edx,labelt                ; pointer to text beginning
  250.     mov  esi,labellen-labelt       ; text length
  251.     int  0x40
  252.  
  253.                                    ; CLOSE BUTTON
  254.     mov  eax,8                     ; function 8 : define and draw button
  255.     mov  ebx,[size_x]
  256.     shr  ebx,2
  257.     add  ebx,40-19
  258.     shl  ebx,16
  259.     mov  bx,12                     ; [x start] *65536 + [x size]
  260.     mov  ecx,5*65536+12            ; [y start] *65536 + [y size]
  261.     xor  edx,edx                   ; button id
  262.     inc  edx
  263.     mov  esi,0x7777dd              ; button color RRGGBB
  264.     int  0x40
  265.  
  266.                                    ; save image
  267.     mov  ebx,20*65536
  268.     mov  bx,word [size_x]
  269.     shr  bx,2
  270.     mov  cx,word [size_y]
  271.     shr  cx,2
  272.     add  cx,49
  273.     shl  ecx,16
  274.     mov  cx,12
  275.     mov  edx,2
  276.     mov  esi,0x4f4f9f
  277.     int  0x40
  278.  
  279.     shr  ecx,16
  280.     mov  ebx,25*65536
  281.     mov  bx,cx
  282.     add  bx,3
  283.     mov  eax,4
  284.     mov  ecx,0xffffff
  285.     mov  edx,savetext
  286.     mov  esi,24 ;22
  287.     int  0x40
  288.  
  289.     call draw_screen
  290.  
  291.     mov  eax,12                    ; function 12:tell os about windowdraw
  292.     mov  ebx,2                     ; 2, end of draw
  293.     int  0x40
  294.  
  295.     ret
  296.  
  297. draw_screen:
  298.  
  299.     pusha
  300.  
  301.     mov  edi,scr
  302.  
  303.     xor  ecx,ecx
  304.     xor  edx,edx
  305.  
  306.     xor  esi,esi
  307.  
  308.   ds1:
  309.  
  310.     mov  eax,35
  311.     mov  ebx,esi
  312.     int  0x40
  313.     stosd
  314.     dec  edi
  315.  
  316.     add  esi,4
  317.     inc  ecx
  318.     cmp  ecx,[cmp_ecx] ; 800/4
  319.     jb   ds1
  320.  
  321.     add  esi,[add_esi] ; 800*3
  322.     xor  ecx,ecx
  323.     inc  edx
  324.     cmp  edx,[cmp_edx] ; 600/4
  325.     jb   ds1
  326.  
  327.     mov  eax,7
  328.     mov  ebx,scr
  329.     mov  ecx,200*65536+160
  330.     mov  ecx,[size_x]
  331.     shr  ecx,2
  332.     shl  ecx,16
  333.     mov  cx,word [size_y]
  334.     shr  cx,2
  335.     mov  edx,20*65536+35
  336.     int  0x40
  337.  
  338.     popa
  339.  
  340.     ret
  341.  
  342. draw_magnify:
  343.  
  344.     pusha
  345.  
  346.     mov  [m_x],dword 0x0
  347.     mov  [m_y],dword 0x0
  348.  
  349.     xor  ecx,ecx
  350.     xor  edx,edx
  351.  
  352.   dm1:
  353.  
  354.     push edx
  355.     mov  eax,edx
  356.     mul  [size_x]
  357.     pop  edx
  358.     add  eax,ecx
  359.  
  360.     mov  ebx,eax
  361.     mov  eax,35
  362.     int  0x40
  363.  
  364.     pusha
  365.     mov  ebx,ecx
  366.     mov  ecx,edx
  367.     shl  ebx,3
  368.     add  ebx,20
  369.     shl  ebx,16
  370.     mov  bx,8
  371.     shl  ecx,3
  372.     add  ecx,35
  373.     shl  ecx,16
  374.     mov  cx,8
  375.  
  376.     mov  edx,eax
  377.     mov  eax,13
  378.     int  0x40
  379.     popa
  380.  
  381.     inc  ecx
  382.     cmp  ecx,40
  383.     jnz  dm1
  384.     xor  ecx,ecx
  385.     inc  edx
  386.     cmp  edx,32
  387.     jnz  dm1
  388.  
  389.     popa
  390.     ret
  391.  
  392. ; DATA AREA
  393.  
  394. i_size   dd  0x1
  395.  
  396. m_x      dd  100
  397. m_y      dd  100
  398.  
  399. cmp_ecx  dd  0
  400. add_esi  dd  0
  401. cmp_edx  dd  0
  402.  
  403. delay    dd  100
  404.  
  405. labelt:
  406.     db   'VIRTUAL SCREEN 2'
  407. labellen:
  408.  
  409. savetext  db  'SAVE AS /HD/1/SCREEN.BMP   '
  410.  
  411. I_END:
  412.  
  413. temp_x dd ?
  414. temp_y dd ?
  415.  
  416. size_x dd ?
  417. size_y dd ?
  418.