Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   BMP VIEWER
  3. ;   modified by Ivan Poddubny
  4. ;
  5. ;   Compile with FASM for Menuet
  6. ;
  7.  
  8.   use32
  9.   org    0x0
  10.   db     'MENUET01'              ; 8 byte id
  11.   dd     0x01                    ; header version
  12.   dd     START                   ; start of code
  13.   dd     I_END                   ; size of image
  14.   dd     0x300000                ; memory for app
  15.   dd     0xfff0                  ; esp
  16.   dd     I_Param , 0x0           ; I_Param , I_Icon
  17.  
  18. include 'lang.inc'
  19. include 'macros.inc'
  20.  
  21.  
  22. START:                          ; start of execution
  23.  
  24.     cmp  dword [I_Param],0
  25.     je   noparam
  26.  
  27.     cmp  dword [I_Param],'BOOT'
  28.     jne  noboot
  29.     call load_image
  30.     call set_as_background
  31.     mov  eax,15
  32.     mov  ebx,4
  33.     mov  ecx,2
  34.     int  0x40
  35.     mov  eax,15
  36.     mov  ebx,3
  37.     int  0x40
  38.  
  39.     or   eax,-1
  40.     int  0x40
  41.   noboot:
  42.  
  43.     mov edi,name_string
  44.     mov al,0
  45.     mov ecx,70
  46.     rep stosb
  47.  
  48.     mov ecx,50
  49.     mov edi,I_Param
  50.     repne scasb
  51.     sub edi,I_Param
  52.     mov ecx,edi
  53.  
  54.     mov esi,I_Param
  55.     mov edi,name_string
  56.     cld
  57.     rep movsb
  58.     call load_image
  59.  
  60.   noparam:
  61.  
  62.     call draw_window            ; at first, draw the window
  63.  
  64. still:
  65.  
  66.     mov  eax,10                 ; wait here for event
  67.     int  0x40
  68.  
  69.     cmp  eax,1                  ; redraw request ?
  70.     je   red
  71.     cmp  eax,2                  ; key in buffer ?
  72.     je   key
  73.     cmp  eax,3                  ; button in buffer ?
  74.     je   button
  75.  
  76.     jmp  still
  77.  
  78.   red:                          ; redraw
  79.     call draw_window
  80.     jmp  still
  81.  
  82.   key:                          ; key
  83.     mov  eax,2                  ; just read it and ignore
  84.     int  0x40
  85.     jmp  still
  86.  
  87.   button:                       ; button
  88.     mov  eax,17                 ; get id
  89.     int  0x40
  90.  
  91.     cmp  ah,1                   ; button id=1 ?
  92.     jne  noclose
  93.     mov  eax,-1                 ; close this program
  94.     int  0x40
  95.   noclose:
  96.  
  97.     cmp  ah,2
  98.     jne  no_file_name
  99.     call read_string
  100.     jmp  still
  101.   no_file_name:
  102.  
  103.     cmp  ah,3
  104.     jne  no_load_image
  105.     call load_image
  106.     call draw_window
  107.     jmp  still
  108.   no_load_image:
  109.  
  110.     cmp  ah,4
  111.     jne  no_setasbackground
  112.     call set_as_background
  113.     jmp  still
  114.   no_setasbackground:
  115.  
  116.     cmp  ah,5
  117.     jne  no_tiled
  118.     mov  eax,15
  119.     mov  ebx,4
  120.     mov  ecx,1
  121.     int  0x40
  122.     mov  eax,15
  123.     mov  ebx,3
  124.     int  0x40
  125.     jmp  still
  126.   no_tiled:
  127.  
  128.     cmp  ah,6
  129.     jne  no_stretch
  130.     mov  eax,15
  131.     mov  ebx,4
  132.     mov  ecx,2
  133.     int  0x40
  134.     mov  eax,15
  135.     mov  ebx,3
  136.     int  0x40
  137.     jmp  still
  138.   no_stretch:
  139.  
  140.  
  141.     jmp  still
  142.  
  143. type        dd 0x0
  144. i_pos       dd 0x0
  145. x_size      dd 0x1
  146. y_size      dd 0x1
  147. bpp         dd 0x24
  148.  
  149. temp dd 999
  150.  
  151. fileinfoblock:
  152.  
  153.     dd  0                       ; 0 = read
  154.     dd  0                       ; first 512 block
  155.     dd  1                       ; number of blocks to read
  156.     dd  0x10000+1024            ; read to
  157.     dd  35                 ; 17000 byte work area
  158. name_string:
  159.     db  '/HARDDISK/FIRST/MENUET/PICS/NEW.BMP',0
  160.     times 100 db 0
  161.  
  162.  
  163. read_header:
  164.  
  165.     pusha
  166.  
  167.     mov  edi,0x10000
  168.     mov  ecx,100
  169.     mov  eax,0
  170.     cld
  171.     rep  stosb
  172.  
  173.     mov  [fileinfoblock+ 8],dword 1
  174.     mov  [fileinfoblock+12],dword 0x10000
  175.  
  176. push dword [name_string-4]
  177. mov [name_string-4],dword 0x20000
  178.     mov  eax,58
  179.     mov  ebx,fileinfoblock
  180.     int  0x40
  181. pop dword [name_string-4]
  182.  
  183.     movzx eax,word [0x10000+0]
  184.     mov   [type],eax
  185.     mov   eax,[0x10000+10]
  186.     mov   [i_pos],eax
  187.     mov   eax,[0x10000+18]
  188.     mov   [x_size],eax
  189.     mov   eax,[0x10000+22]
  190.     mov   [y_size],eax
  191.     movzx eax,word [0x10000+28]
  192.     mov   [bpp],eax
  193.  
  194.     popa
  195.     ret
  196.  
  197.  
  198. draw_picture_info:
  199.  
  200.     pusha
  201.  
  202.     mov  eax,13
  203.     mov  ebx,380*65536+6*5
  204.     mov  ecx,65*65536+40
  205.     mov  edx,0xffffff
  206.     int  0x40
  207.  
  208.     mov  eax,47
  209.     mov  ebx,5*65536
  210.     mov  ecx,[x_size]
  211.     mov  edx,380*65536+65
  212.     mov  esi,0x224466
  213.     int  0x40
  214.  
  215.     mov  ecx,[y_size]
  216.     add  edx,10
  217.     int  0x40
  218.  
  219.     mov  ecx,[bpp]
  220.     add  edx,20
  221.     int  0x40
  222.  
  223.     popa
  224.     ret
  225.  
  226.  
  227.  
  228. load_image:
  229.  
  230.     pusha
  231.  
  232.     call read_header
  233.  
  234.     cmp  word [type],'BM'
  235.     je   ok_image
  236.  
  237.     cmp  [bpp],24
  238.     je   ok_image
  239.  
  240.     mov  eax,13                  ; not found !
  241.     mov  ebx,150*65536+50
  242.     mov  ecx,100*65536+50
  243.     mov  edx,0xff0000
  244.     int  0x40
  245.  
  246.     mov  eax,5
  247.     mov  ebx,100
  248.     int  0x40
  249.  
  250.     jmp  retimage
  251.  
  252.   ok_image:
  253.  
  254.     call draw_picture_info
  255.  
  256.     mov  [fileinfoblock+8],dword 0x100000/512
  257.     mov  eax,0x80000
  258.     sub  eax,[i_pos]
  259.     mov  [fileinfoblock+12],eax
  260. push dword [name_string-4]
  261. mov [name_string-4],dword 0x20000
  262.     mov  eax,58
  263.     mov  ebx,fileinfoblock
  264.     int  0x40
  265. pop dword [name_string-4]
  266.  
  267.     mov  eax,[x_size]
  268.     imul eax,3
  269.  
  270.     mov  [x_delta],eax
  271.  
  272.     mov  ebx,[y_size]
  273.     dec  ebx
  274.     imul eax,ebx
  275.     add  eax,0x80000
  276.  
  277.     mov  esi,eax
  278.     mov  edi,0x180000
  279.   newln:
  280.     push esi
  281.     push edi
  282.     mov  ecx,[x_delta]
  283.     cld
  284.     rep  movsb
  285.     pop  edi
  286.     pop  esi
  287.  
  288.     sub  esi,[x_delta];640*3
  289.     add  edi,[x_delta];640*3
  290.     cmp  esi,0x80000
  291.     jge  newln
  292.  
  293.   retimage:
  294.  
  295.     popa
  296.  
  297.     ret
  298.  
  299. x_delta dd 0x1
  300.  
  301.  
  302. draw_image:
  303.  
  304.     pusha
  305.  
  306. ;    mov  eax,7                     ; draw with putimage
  307. ;    mov  ebx,0x180000
  308. ;    mov  ecx,200*65536+160
  309. ;    mov  edx,14*65536+28
  310. ;    int  0x40
  311. ;    mov  eax,5
  312. ;    mov  ebx,200
  313. ;    int  0x40
  314.  
  315.     mov  ebx,0   ; show the image as 320x240 picture
  316.     mov  ecx,0
  317.  
  318. times 6 db 0x90
  319.  
  320.   newpix:
  321.  
  322.     push ebx
  323.     push ecx
  324.  
  325.     mov  eax,[esp]
  326.     imul eax,[y_size]
  327.  
  328.     mov  ebx,240
  329.     xor  edx,edx
  330.     div  ebx
  331.  
  332.     imul eax,3
  333.     imul eax,[x_size]
  334.  
  335.     mov  esi,eax
  336.  
  337.     mov  eax,[esp+4]
  338.     imul eax,[x_size]
  339.  
  340.     mov  ebx,320
  341.     xor  edx,edx
  342.     div  ebx
  343.  
  344.     imul eax,3
  345.  
  346.     add  esi,eax
  347.     mov  edx,[0x180000+esi]
  348.  
  349.  
  350.     and  edx,0xffffff
  351.  
  352.     pop  ecx
  353.     pop  ebx
  354.  
  355.     add  ebx,20
  356.     add  ecx,40
  357.     mov  eax,1
  358.     int  0x40
  359.     add  ebx,-20
  360.     add  ecx,-40
  361.  
  362.     inc  ebx
  363.     cmp  ebx,320
  364.     jb   newpix
  365.  
  366.     xor  ebx,ebx
  367.  
  368.     inc  ecx
  369.     cmp  ecx,240
  370.     jb   newpix
  371.  
  372.     popa
  373.  
  374.     ret
  375.  
  376. set_as_background:
  377.  
  378.     pusha
  379.  
  380.     mov  esi,0x180000
  381.   new_smooth:
  382.     xor  eax,eax
  383.     xor  ebx,ebx
  384.     mov  al,[esi]
  385.     mov  bl,[esi+3]
  386.     add  eax,ebx
  387.     mov  bl,[esi+6]
  388.     add  eax,ebx
  389.     mov  bl,[esi+9]
  390.     add  eax,ebx
  391.     shr  eax,2
  392.     and  eax,0xff
  393.     inc  esi
  394.     cmp  esi,0x180000+640*480*3
  395.     jbe  new_smooth
  396.  
  397.  
  398.     mov  eax,15
  399.     mov  ebx,1
  400.     mov  ecx,[x_size]
  401.     mov  edx,[y_size]
  402.     int  0x40
  403.  
  404.     mov  eax,15
  405.     mov  ebx,5
  406.     mov  ecx,0x180000
  407.     mov  edx,0
  408.     mov  esi,640*480*3
  409.     int  0x40
  410.  
  411.     mov  eax,15
  412.     mov  ebx,3
  413.     int  0x40
  414.  
  415.  
  416.     popa
  417.  
  418.     ret
  419.  
  420. ya   dd 300
  421. addr dd name_string
  422. case_sens db 0
  423.  
  424.  
  425. read_string:
  426. pusha
  427.  
  428. mov edi,[addr]
  429. mov eax,[addr]
  430. mov eax,[eax-4]
  431. mov [temp],eax
  432.  
  433. add edi,eax
  434.  
  435. call print_strings
  436.  
  437. f11:
  438. mov eax,10
  439. int 0x40
  440. cmp eax,2
  441. jne read_done
  442. int 0x40
  443. shr eax,8
  444.  
  445. cmp eax,13
  446. je read_done
  447.  
  448. cmp eax,192
  449. jne noclear
  450.  
  451. xor eax,eax
  452. mov [temp],eax
  453. mov edi,[addr]
  454. mov [edi-4],eax
  455. mov ecx,49
  456. cld
  457. rep stosb
  458. mov edi,[addr]
  459. call print_strings
  460. jmp f11
  461.  
  462. noclear:
  463.  
  464. cmp eax,8
  465. jnz nobsl
  466. cmp [temp],0
  467. jz f11
  468. dec [temp]
  469. mov edi,[addr]
  470. add edi,[temp]
  471. mov [edi],byte 0
  472.  
  473. mov eax,[addr]
  474. dec dword [eax-4]
  475.  
  476. call print_strings
  477. jmp f11
  478.  
  479. nobsl:
  480. cmp [temp],50
  481. jae read_done
  482.  
  483. cmp eax,dword 31
  484. jbe f11
  485. cmp [case_sens],1
  486. je keyok
  487. cmp eax,dword 95
  488. jb keyok
  489. add eax,-32
  490. keyok:
  491. mov edi,[addr]
  492. add edi,[temp]
  493. mov [edi],al
  494.  
  495. inc [temp]
  496.  
  497. mov eax,[addr]
  498. inc dword [eax-4]
  499. call print_strings
  500. cmp [temp],50
  501. jbe f11
  502.  
  503. read_done:
  504. mov ecx,50
  505. sub ecx,[temp]
  506. mov edi,[addr]
  507. add edi,[temp]
  508. xor eax,eax
  509. cld
  510. rep stosb
  511.  
  512. mov [temp],999
  513.  
  514. call print_strings
  515.  
  516. popa
  517. ret
  518.  
  519. print_strings:
  520. pusha
  521. mov eax,13
  522. mov ebx,80*65536+6*45
  523. mov ecx,[ya]
  524. shl ecx,16
  525. add ecx,12
  526. mov edx,0xffffff
  527. int 0x40
  528.  
  529. mov edx,[addr]
  530. mov esi,[edx-4]
  531. mov eax,4
  532. mov ebx,80*65536+2
  533. add ebx,[ya]
  534. mov ecx,0
  535. int 0x40
  536.  
  537. cmp [temp],50
  538. ja @f
  539.  
  540. mov eax,[ya]
  541. mov ebx,eax
  542. shl eax,16
  543. add eax,ebx
  544. add eax,10
  545. mov ecx,eax
  546.  
  547. mov eax,[temp]
  548. imul eax,eax,6
  549. add eax,80
  550. mov ebx,eax
  551. shl eax,16
  552. add ebx,eax
  553.  
  554. mov eax,38
  555. mov edx,0
  556. int 0x40
  557. @@:
  558.  
  559. popa
  560. ret
  561.  
  562.  
  563.  
  564.  
  565. ;   *********************************************
  566. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  567. ;   *********************************************
  568.  
  569.  
  570. draw_window:
  571.  
  572.     mov  eax,12                    ; function 12:tell os about windowdraw
  573.     mov  ebx,1                     ; 1, start of draw
  574.     int  0x40
  575.  
  576.                                    ; DRAW WINDOW
  577.     mov  eax,0                     ; function 0 : define and draw window
  578.     mov  ebx,20*65536+444          ; [x start] *65536 + [x size]
  579.     mov  ecx,10*65536+333          ; [y start] *65536 + [y size]
  580.     mov  edx,0x03ffffff            ; color of work area RRGGBB,8->color gl
  581.     mov  esi,0x808899ff            ; color of grab bar  RRGGBB,8->color gl
  582.     mov  edi,0x008899ff            ; color of frames    RRGGBB
  583.     int  0x40
  584.  
  585.                                    ; WINDOW LABEL
  586.     mov  eax,4                     ; function 4 : write text to window
  587.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  588.     mov  ecx,0x10ddeeff            ; color of text RRGGBB
  589.     mov  edx,labelt                ; pointer to text beginning
  590.     mov  esi,labellen-labelt       ; text length
  591.     int  0x40
  592.  
  593.     mov  eax,8
  594.     mov  ebx,20*65536+52
  595.     mov  ecx,295*65536+16
  596.     mov  edx,2
  597.     mov  esi,0x306090
  598.     int  0x40
  599.  
  600.     add  ebx,336*65536+20
  601.     add  ecx,5*65536
  602.     mov  edx,3
  603.     int  0x40
  604.  
  605.     sub  ecx,20*65536
  606.     mov  edx,4
  607.     int  0x40
  608.  
  609.     sub  ecx,40*65536
  610.     inc  edx
  611.     int  0x40
  612.  
  613.     add  ecx,20*65536
  614.     inc  edx
  615.     int  0x40
  616.  
  617.     mov  ebx,346*65536+45
  618.     mov  edx,info+1
  619.     mov  esi,15
  620.   newinfo:
  621.     mov  ecx,[tcolor]
  622.     cmp  [edx-1],byte 'w'
  623.     jne  nowhite
  624.     mov  ecx,[btcolor]
  625.   nowhite:
  626.     mov  eax,4
  627.     int  0x40
  628.     add  ebx,10
  629.     add  edx,16
  630.     cmp  [edx-1],byte 'x'
  631.     jne  newinfo
  632.  
  633.     mov  ebx,20*65536+300           ; draw info text with function 4
  634.     mov  ecx,[btcolor]
  635.     mov  edx,text
  636.     mov  esi,70
  637.   newline:
  638.     mov  eax,4
  639.     int  0x40
  640.     add  ebx,10
  641.     add  edx,esi
  642.     cmp  [edx],byte 'x'
  643.     jne  newline
  644.  
  645.     call print_strings
  646.  
  647.     call draw_image
  648.  
  649.     call draw_picture_info
  650.  
  651.     mov  eax,12                    ; function 12:tell os about windowdraw
  652.     mov  ebx,2                     ; 2, end of draw
  653.     int  0x40
  654.  
  655.     ret
  656.  
  657.  
  658. ; DATA AREA
  659.  
  660. tcolor   dd  0x000000
  661. btcolor  dd  0x224466+0x808080
  662.  
  663.  
  664. text:
  665.  db '  FILE:                                                               '
  666.  db 'x'
  667.  
  668. info:
  669.  db '  IMAGE INFO    '
  670.  db '                '
  671.  db '  X:            '
  672.  db '  Y:            '
  673.  db '                '
  674.  db '  BPP:          '
  675.  db '                '
  676.  db '                '
  677.  db '  16M COLOURS   '
  678.  db '  640x480 max   '
  679. times 10 db '                '
  680.  db 'w     TILED     '
  681.  db '                '
  682.  db 'w    STRETCH    '
  683.  db '                '
  684.  db 'w   SET AS BGR  '
  685.  db '                '
  686.  db 'w      LOAD     '
  687.  db 'x'
  688.  
  689.  
  690. labelt:    db   'BMP VIEWER'
  691. labellen:
  692.  
  693. I_END:
  694. I_Param:
  695.