kolibrios/programs/media/paint/trunk/PAINT.ASM
Kirill Lipatov (Leency) b7c1c94b59 keybi, simple paint: use skinned windows
git-svn-id: svn://kolibrios.org@6165 a494cfbc-eb01-0410-851d-a64ba20cac60
2016-02-07 19:54:43 +00:00

332 lines
11 KiB
NASM
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;*********************************
;* *
;* PAINT 0.02 ¤«ï MenuetOS *
;* *
;* Š®¬¯¨«¨à®¢ âì FASM'®¬ *
;* *
;*********************************
;******************************************************************************
; <20>â㠯ணࠬ¬ã ­¥ ­ã¦­® á¥à쥧­® à áᬠâਢ âì - íâ® ¢á¥£® «¨èì ¯à¨¬¥à,
; ¢ ª®â®à®¬ ¯®ª § ­®, ª ª à ¡®â âì á ­¥ª®â®à묨 á¨á⥬­ë¬¨ äã­ªæ¨ï¬¨ Œ¥Ž‘,
; ­® ­¨ª ª ­¥ ­®à¬ «ì­ë© £à ä¨ç¥áª¨© । ªâ®à. Š®¤ ¯à®£à ¬¬ë Ž—…<E28094>œ ¯à®á⮩,
; ¨ ®­  ¯à¥¤­ §­ ç¥­  ¤«ï â¥å, ªâ® ⮫쪮 ­ ç¨­ ¥â ¨§ãç âì  áᥬ¡«¥à,
; ¯®í⮬ã ï áâ६¨«áï ᤥ« âì ¥£® ª ª ¬®¦­® ¡®«¥¥ ¯®­ïâ­ë¬.
; ’¥¬ ­¥ ¬¥­¥¥, ª®¤ ¤®¢®«ì­® ­¥¯«®å® ®¯â¨¬¨§¨à®¢ ­, å®âï íâ® ­¥¬­®£®
; ¬®¦¥â § âà㤭¨âì ¥£® ¯®­¨¬ ­¨¥. Ÿ ¯®áâ à «áï âé â¥«ì­® ¯à®ª®¬¬¥­â¨à®¢ âì
; á«®¦­ë¥ ¬¥áâ . Šáâ â¨, ¨¤¥ï ¯à®£à ¬¬ë ¯à¨­ ¤«¥¦¨â ­¥ ¬­¥,   Sniper'ã, ¤«ï
; ª®â®à®£® ¢®¡é¥¬-â® ¢á¥ ¨ ¯¨á «®áì.
; “¤ ç¨ ¢ ¨§ã祭¨¨  á¬ !
; ˆ¢ ­ <20>®¤¤ã¡­ë©, ivan-yar@bk.ru
;******************************************************************************
; <20>®¤ª«îç ¥¬ ­¥®¡å®¤¨¬ë¥ ¬ ªà®áë
include '../../../macros.inc'
;******************************************************************************
; <20>€—€Ž <20><>Žƒ<C5BD>€ŒŒ
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; title version
dd START ; start of code
dd I_END ; size of image
dd E_END ; memory for app
dd E_END ; esp
dd 0x0,0x0 ; I_Param , I_Icon
; Ž<>œ ŠŽ„€
START:
mov eax,40 ; á®®¡é¨¬ á¨á⥬¥, ª ª¨¥ ᮡëâ¨ï ¡ã¤¥¬ ®¡à ¡ â뢠âì
mov ebx,0100101b ; ¬ áª  ᮡë⨩ - ¯¥à¥à¨á®¢ª  (1) + ª­®¯ª  (3) + ¬ëèì (6
int 0x40 ; íâ  ª®¬ ­¤  ¢ë§ë¢ ¥â á¨á⥬­ãî äã­ªæ¨î
mov [workarea.cx],5 ; ª®®à¤¨­ âë à ¡®ç¥© (ª«¨¥­â᪮©) ®¡« áâ¨
mov [workarea.cy],30 ; ¤«ï à¨á®¢ ­¨ï
red:
call draw_window ; ¢ë§ë¢ ¥¬ ¯à®æ¥¤ãàã ®âà¨á®¢ª¨ ®ª­ 
still: ; ƒ<E282AC>‰ –ˆŠ‹ <20><>Žƒ<C5BD>€ŒŒ - –ˆŠ‹ Ž<><C5BD><EFBFBD>ŽŠˆ ŽŽ<C5BD>™…<E284A2>ˆ
mov eax,10 ; äã­ªæ¨ï 10 - ¦¤ âì ᮡëâ¨ï; ¯à®£à ¬¬  ®áâ ­ ¢«¨¢ ¥âáï ­ 
int 0x40 ; á«¥¤ãîé ï ª®¬ ­¤  ­¥ ¡ã¤¥â ¢ë¯®«­¥­  ¤® â¥å ¯®à, ¯®ª 
; ­¥ ¯à®¨§®©¤ñâ ᮡë⨥
; ⥯¥àì ॣ¨áâà eax ᮤ¥à¦¨â ­®¬¥à ᮡëâ¨ï
; ¯®®ç¥à¥¤­® áà ¢­¨¬ ¥£® á® ¢á¥¬¨ ¢®§¬®¦­ë¬¨ §­ ç¥­¨ï¬¨, çâ®¡ë ¢ë§¢ âì
; ­ã¦­ë© ®¡à ¡®â稪
cmp eax,1 ; ¯¥à¥à¨á®¢ âì ®ª­® ?
je red ; ¥á«¨ ॣ¨áâà eax à ¢¥­ ¥¤¨­¨æ¥, â® ¯¥à¥å®¤¨¬ ­  ¬¥âªã red
cmp eax,3 ; ­ ¦ â  ª­®¯ª  ?
je button
cmp eax,6 ; ¬ëèì?
je mouse
jmp still ; ¥á«¨ ¯à®¨§®è«® ᮡë⨥, ª®â®à®¥ ¬ë ­¥ ®¡à ¡ â뢠¥¬,
; ¯à®áâ® ¢®§¢à é ¥¬áï ª ­ ç «ã 横« , å®âï â ª®£® ¡ëâì
; ­¥ ¤®«¦­®! .¥. ¥á«¨ íâã ª®¬ ­¤ã ®âá ã¡à âì, â®
; ­¨ç¥£® áâà è­®£® ­¥ á«ãç¨âáï.
;******************************************************************************
button: ; ®¡à ¡®â稪 ­ ¦ â¨ï ª­®¯ª¨ ¢ ®ª­¥ ¯à®£à ¬¬ë
mov eax,17 ; äã­ªæ¨ï N17 - ¯®«ãç¨âì ¨¤¥­â¨ä¨ª â®à ­ ¦ â®© ª­®¯ª¨
int 0x40
; ⥯¥àì ¢ ॣ¨áâॠah ᮤ¥à¦¨âáï ¨¤¥­â¨ä¨ª â®à.
shr eax,8 ; ah -> al (ᤢ¨£ ­  8 ¡¨â ¢¯à ¢®)
dec al ; ¨¤¥­â¨ä¨ª â®à_ª­®¯ª¨--;
jnz .noclose ; ¥á«¨ १ã«ìâ â ¯à¥¤ë¤ã饩 ª®¬ ­¤ë à ¢¥­ ­ã«î, § ªà뢠¥¬áï
; ¨­ ç¥ - ¨¤ñ¬ ­  ¬¥âªã noclose
or eax,-1 ; ¢ë室 ¨§ ¯à®£à ¬¬ë
int 0x40
.noclose:
; ¥á«¨ ¬ë á ¯®¯ «¨, §­ ç¨â ¨¤¥­â¨ä¨ª â®à ª­®¯ª¨ ­¥ ¡ë« à ¢¥­ ­ã«î...
; ⥯¥àì ã ­ á ¢ eax ᮤ¥à¦¨âáï (­®¬¥à 梥⭮© ª­®¯ª¨ - 1),
; â.¥ ¨«¨ 1, ¨«¨ 2, ... ,¨«¨ 5
; 㬥­ì訬 ­  1:
dec eax
; ¢®â íâ  ¢®â ª®¬ ­¤  ¨§¢«¥ª ¥â ¢ eax ¤¢®©­®¥ á«®¢® ¯®  ¤à¥áã colors+eax*4
; £¤¥ colors - ᬥ饭¨¥ ¬¥âª¨ colors, ¯®á«¥ ª®â®à®© ¨¤¥â ¯®á«¥¤®¢ â¥«ì­®áâì
; 梥⮢, eax*4 - ­®¬¥à 梥â , 㬭®¦¥­­ë© ­  4, â.ª. ­  ®¤¨­ 梥⠭㦭®
; ç¥âëॠ¡ ©â .
mov eax,[colors+eax*4]
; ⥯¥àì ¬ë ãáâ ­®¢¨¬ 梥â, ᮤ¥à¦ é¨©áï ¢ ॣ¨áâॠeax ª ª ®á­®¢­®©:
mov [active_color],eax
; ­ã ¢®â, ᮡá⢥­­®, ¨ ¢áñ, çâ® ®â ­ á âॡ®¢ «®áì ;)
; ¢¥à­ñ¬áï ª ­ ç «ã 横«  ®¡à ¡®âª¨ ᮡë⨩
jmp still
;******************************************************************************
mouse: ; ®¡à ¡®â稪 ¬ëè¨
mov eax,37 ; á­ ç «  ¯®«ã稬 ⥪ã騥 ª®®à¤¨­ âë ¬ëè¨
mov ebx,1
int 0x40
mov ebx,eax ; ¯à¥®¡à §ã¥¬ ¨å
shr eax,16 ; eax=x;
and ebx,0xffff ; ebx=y;
cmp ebx,22
jb save_canvas
sub eax,[workarea.cx] ; x-=[workarea.cx]
cmp eax,0 ; ¥á«¨ ¬ëèì «¥¢¥¥ ª«¨¥­â᪮© ®¡« áâ¨,
jle .not_pressed ; ­¨ç¥£® ­¥ à¨á㥬
cmp eax,[workarea.sx] ; ¥á«¨ ¬ëèì ¯à ¢¥¥...
jae .not_pressed
sub ebx,[workarea.cy]
cmp ebx,0 ; ...¢ëè¥...
jle .not_pressed
cmp ebx,[workarea.sy] ; ...­¨¦¥...
jae .not_pressed
; ª ª¨¥ ª­®¯ª¨ ­ ¦ âë?
mov eax,37
mov ebx,2
int 0x40
; ¥á«¨ «¥¢ ï ª­®¯ª  (â.¥. eax = 1), ⥠¯®©¤ñ¬ ¤ «ìè¥
cmp eax,1
je .leftbtn
.not_pressed:
; ‹¥¢ ï ª­®¯ª  ­¥ ­ ¦ â , § ¯®¬­¨¬ ⥪ã騥 ª®®à¤¨­ âë ¨ ¡ã¤¥¬ ¦¤ âì ᮡëâ¨ï
mov [mouse_pressed],0 ; ¬ëèì ­¥ ­ ¦ â 
mov eax,37 ; ¯®«ã稬 ª®®à¤¨­ âë
mov ebx,1
int 0x40
mov ebx,eax
shr eax,16
and ebx,0xffff
mov [old_x],eax ; § ¯®¬­¨¬ ¨å
mov [old_y],ebx
jmp still
.leftbtn:
; ‹¥¢ ï ª­®¯ª  ­ ¦ â , ­ ¤® íâ® § ¯¨á âì!
mov [mouse_pressed],1
; <20>®«ã稬 ª®®à¤¨­ âë ªãàá®à  ¬ëè¨ (®â­®á¨â¥«ì­® ®ª­ )
mcall 37,1 ; ¯®«ãç¨âì á®áâ®ï­¨¥ ¬ëè¨
; <20>¥à¥¤¥« ¥¬ ¨å â ª, çâ®¡ë ®­¨ ¡ë«¨ ¢ à §­ëå ॣ¨áâà å, â.¥. eax ¨ ebx
mov ebx,eax
shr eax,16
and ebx,0xffff
; <20>®¤£®â®¢¨¬ ¯ à ¬¥âàë ¤«ï ä㭪樨 à¨á®¢ ­¨ï «¨­¨¨
mov ecx,[old_x] ; ¤«ï ­ ç «  § £à㧨¬ áâ àë¥ ª®®à¤¨­ âë
mov edx,[old_y]
mov [old_x],eax ; ⥯¥àì á®åà ­¨¬ ⥪ã騥 ¢ áâ àë¥
mov [old_y],ebx
shl ecx,16 ; ¢ ¢¥àå­¥¥ á«®¢® ­ ç «ì­ë¥ (⥪ã騥) ª®®à¤¨­ âë
shl edx,16
add eax,ecx ;   ¢ ­¨¦­¥¥ á«®¢® ª®­¥ç­ë¥, â.¥. áâ àë¥
add ebx,edx
mov ecx,ebx ; ¯®¬¥­ï¥¬ ॣ¨áâàë â ª, ª ª íâ㠭㦭® 38 ä㭪樨
mov ebx,eax
mov eax,38 ; ­®¬¥à ä㭪樨 ¢ eax
mov edx,[active_color] ; ¢ edx 梥â
int 0x40
;  - ¯®¯à®¡ã©â¥ ¯®áâ ¢¨âì ¤à㣨¥ §­ ç¥­¨ï (00090001)
mov edi,0x00010001 ; çâ®¡ë «¨­¨ï ­¥ ¡ë«  ᫨誮¬ â®­ª®©,
add ebx,edi ; ­ à¨á㥬 à冷¬ ¥é¥ 3!
int 0x40
add ecx,edi
int 0x40
sub ebx,edi
int 0x40
sub ebx,edi ; ­ã   ç⮡ë ᬮâ५®áì ᮢᥬ ªàãâ®,
int 0x40 ; ¤®à¨á㥬 ¥é¥ 5!
sub ecx,edi
int 0x40
sub ecx,edi
int 0x40
add ebx,edi
int 0x40
add ebx,edi
int 0x40
jmp still
;******************************************************************************
save_canvas:
mov eax,[proc_info.box.width]
add eax,[workarea.cx]
mov ebx,[proc_info.box.height]
add ebx,[workarea.cy]
jmp still
;******************************************************************************
; *********************************************
; ******* Ž<><C5BD>…„…<E280B9>ˆˆ Ž<C5BD>ˆŽŠ€ ŽŠ<C5BD>€ *******
; *********************************************
draw_window:
mcall 48,3,sc,sizeof.system_colors ; <20>Ž„ƒ<E2809E>“†€…Œ ˆ…Œ<E280A6>… –‚…’€
mcall 12, 1 ; ­ ç «® ®âà¨á®¢ª¨ ®ª­ 
mov edx, [sc.work]
or edx, 0x33000000
mcall 0, (100 shl 16)+400, (100 shl 16)+300, , , title ; à¨á㥬 ®ª­®
mcall 12, 1
mcall 9,proc_info,-1 ; ¯®«ã稬 ¨­ä®à¬ æ¨î ® ᢮¥¬ ¯®â®ª¥
mov eax,[proc_info.box.width] ; ­ áâந¬ à §¬¥à à ¡®ç¥© ®¡« áâ¨
sub eax,20 ; (å à §¬¥à ®ª­  - 20)
mov [workarea.sx],eax
mov eax,[proc_info.box.height]
sub eax,63 ; (ã à §¬¥à - 63)
mov [workarea.sy],eax
cmp [proc_info.box.height],80
jb .finish
mov eax, 8
mov edx, 1
; ᮧ¤ ñ¬ ª­®¯ª¨ ¢ë¡®à  梥â :
mov ebx,10*65536+15 ; ­ ç «ì­ ï x ª®®à¤¨­ â  ¨ à §¬¥à
mov ecx, 7*65536+15 ; ­ ç «ì­ ï y ª®®à¤¨­ â  & size
.new_button:
inc edx ; ¨¤¥­â¨ä¨ª â®à++;
mov esi,[btn_colors-8+edx*4] ; 梥⠪­®¯ª¨
int 0x40 ; áâ ¢¨¬ ª­®¯ªã
add ebx,18*65536 ; á«¥¤ãîé ï ª­®¯ª  ¯à ¢¥¥ ­  12
cmp edx,9 ; áà ¢­¨¢ ¥¬ edx (¨¤¥­â¨ä¨ª â®à) á 9
jbe .new_button ; ¥á«¨ ¬¥­ìè¥ ¨«¨ à ¢­® -> ¥éñ ®¤­ã ª¯®ªã
mov eax,13 ; ç¨á⨬ "宫áâ" - ª«¨¥­âáªãî ®¡« áâì
mov ebx,[workarea.cx]
mov ecx,[workarea.cy]
shl ebx,16
shl ecx,16
add ebx,[workarea.sx]
add ecx,[workarea.sy]
mov edx,0xffffff
mcall 13
.finish:
ret
;******************************************************************************
; ­ ç «® ®¡« á⨠¨­¨æ¨ «¨§¨à®¢ ­­ëå ¤ ­­ëå
; ¥á«¨ ªâ® ¥éñ ­¥ §­ ¥â, çâ® §­ ç¨â "¨­¨æ¨ «¨§¨à®¢ ­­ë¥", â® ¯®ïá­ïî:
; í⮠⥠¤ ­­ë¥, ª®â®àë¬ ¯à¨á¢®¥­® ­ ç «ì­®¥ §­ ç¥­¨¥
;data
title db 'Simple Paint v0.3',0
mouse_pressed db 0 ; ¯®ª §ë¢ ¥â, ­ ¦ â  «¨ ¡ë«  ¬ëèì ¢ ¯à¥¤ë¤ã騩 ¬®¬¥­â
; æ¢¥â  ª­®¯®ª
btn_colors:
dd 0xdddddd ; white
dd 0x444444 ; black
dd 0x00dd00 ; green
dd 0x0000dd ; blue
dd 0xdd0000 ; red
dd 0xdd00dd ; magenta
dd 0xdddd00 ; yellow
dd 0x00dddd ; cyan
dd 0x559955 ; warm green
; æ¢¥â  ª¨á⨠(¢ ⮬ ¦¥ ¯®à浪¥, çâ® ¨ æ¢¥â  ª­®¯®ª)
colors:
dd 0xffffff ; ¡¥«ë©
dd 0x000000 ; ç¥à­ë©
dd 0x00ff00 ; §¥«¥­ë©
dd 0x0000ff ; ᨭ¨©
dd 0xff0000 ; ªà á­ë©
dd 0xff00ff ; ¯ãà¯ãà­ë©
dd 0xffff00 ; ¦¥«âë©
dd 0x00ffff ; £®«ã¡®©
dd 0x77bb77 ; ⥯«ë© §¥«¥­ë©
;******************************************************************************
;   ¢®â âãâ ­ ç¨­ ¥âáï ®¡« áâì <20>…¨­¨æ¨ «¨§¨à®¢ ­­ëå ¤ ­­ëå, â.¥.
; §¤¥áì ¤ ­­ë¬ §­ ç¥­¨ï ­¥ ¯à¨á¢®¥­ë. ®â«¨ç¨¥ ®â ¨­¨æ., ­¥ 㢥«¨ç¨¢ îâ à §¬¥à
; ä ©« 
I_END:
active_color dd ? ;  ªâ¨¢­ë© 梥â
old_x dd ? ; áâ àë¥ ª®®à¤¨­ âë ¬ëè¨
old_y dd ?
workarea: ; ª®®à¤¨­ âë ¨ à §¬¥àë ª«¨¥­â᪮© ®¡« áâ¨
.cx dd ? ; c - ª®®¤¨­ âë
.cy dd ?
.sx dd ? ; s - à §¬¥àë
.sy dd ?
sc system_colors ; á¨á⥬­ë¥ 梥â 
proc_info process_information ; ¨­ä®à¬ æ¨ï ® ¯à®æ¥áá¥
restflag dd ?
canvas rb 800*600*3
E_END: