kolibrios-fun/programs/media/paint/trunk/PAINT.ASM
Yogev Ezra de447bcec4 Add some more sources from MENUET32
git-svn-id: svn://kolibrios.org@3497 a494cfbc-eb01-0410-851d-a64ba20cac60
2013-05-09 18:49:02 +00:00

366 lines
12 KiB
NASM
Raw 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>€ŒŒ
meos_app_start
; Ž<>œ ŠŽ„€
code
mov eax,40 ; á®®¡é¨¬ á¨á⥬¥, ª ª¨¥ ᮡëâ¨ï ¡ã¤¥¬ ®¡à ¡ â뢠âì
mov ebx,0100101b ; ¬ áª  ᮡë⨩ - ¯¥à¥à¨á®¢ª  (1) + ª­®¯ª  (3) + ¬ëèì (6
int 0x40 ; íâ  ª®¬ ­¤  ¢ë§ë¢ ¥â á¨á⥬­ãî äã­ªæ¨î
mov [workarea.cx],10 ; ª®®à¤¨­ âë à ¡®ç¥© (ª«¨¥­â᪮©) ®¡« áâ¨
mov [workarea.cy],45 ; ¤«ï à¨á®¢ ­¨ï
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>®«ã稬 ª®®à¤¨­ âë ªãàá®à  ¬ëè¨ (®â­®á¨â¥«ì­® ®ª­ )
mov eax,37 ; äã­ªæ¨ï 37 - ¯®«ãç¨âì á®áâ®ï­¨¥ ¬ëè¨
mov ebx,1 ; ¯®¤äã­ªæ¨ï 1
int 0x40
; <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,[process.x_size]
add eax,[workarea.cx]
mov ebx,[process.y_size]
add ebx,[workarea.cy]
jmp still
;******************************************************************************
; *********************************************
; ******* Ž<><C5BD>…„…<E280B9>ˆˆ Ž<C5BD>ˆŽŠ€ ŽŠ<C5BD>€ *******
; *********************************************
draw_window:
mov eax,48 ; <20>Ž„ƒ<E2809E>“†€…Œ ˆ…Œ<E280A6>… –‚…’€
mov ebx,3
mov ecx,sc
mov edx,sizeof.system_colors
int 0x40
mov eax,12 ; äã­ªæ¨ï 12: á®®¡é¨âì Ž‘ ®¡ ®âà¨á®¢ª¥ ®ª­ 
mov ebx,1 ; 1, ­ ç¨­ ¥¬ à¨á®¢ âì
int 0x40
; ‘Ž‡„€ðŒ ŽŠ<C5BD>Ž
mov eax,0 ; äã­ªæ¨ï 0 : ®¯à¥¤¥«¨âì ¨ ®âà¨á®¢ âì ®ª­®
mov ebx,100*65536+400 ; [x áâ àâ] *65536 + [x à §¬¥à]
mov ecx,100*65536+300 ; [y áâ àâ] *65536 + [y à §¬¥à]
mov edx,[sc.work] ; 梥â à ¡®ç¥© ®¡« á⨠RRGGBB,8->color gl
or edx,0x02000000
mov esi,[sc.grab] ; 梥⠯®«®áë § £®«®¢ª  RRGGBB,8->color gl
or esi,0x80000000
mov edi,[sc.frame] ; 梥â à ¬ª¨ RRGGBB
int 0x40
mov eax,9 ; ¯®«ã稬 ¨­ä®à¬ æ¨î ® ᥡ¥
mov ebx,process
mov ecx,-1
int 0x40
mov eax,[process.x_size] ; ­ áâந¬ à §¬¥à à ¡®ç¥© ®¡« áâ¨
add eax,-20 ; (å à §¬¥à ®ª­  - 20)
mov [workarea.sx],eax ;
mov eax,[process.y_size] ;
add eax,-60 ; (ã à §¬¥à - 60)
mov [workarea.sy],eax ;
; ‡€ƒŽ‹Ž‚ŽŠ ŽŠ<C5BD>
mov eax,4 ; äã­ªæ¨ï 4 : ­ ¯¨á âì ¢ ®ª­¥ ⥪áâ
mov ebx,8*65536+8 ; [x] *65536 + [y]
mov ecx,[sc.grab_text] ; 梥â
or ecx,0x10000000 ; èà¨äâ
mov edx,header ;  ¤à¥á áâப¨
mov esi,header_len ; ¨ ¥ñ ¤«¨­ 
int 0x40
; Š<>Ž<EFBFBD>Š€ ‡€Š<E282AC>ˆŸ ŽŠ<C5BD>
mov eax,8 ; äã­ªæ¨ï 8 : ®¯à¥¤¥«¨âì ¨ ­ à¨á®¢ âì ª­®¯ªã
; mov ebx,(300-19)*65536+12 ; [x áâ àâ] *65536 + [x à §¬¥à]
mov ebx,[process.x_size]
add ebx,-19
shl ebx,16
add ebx,12
mov ecx,5*65536+12 ; [y áâ àâ] *65536 + [y à §¬¥à]
mov edx,1 ; ¨¤¥­â¨ä¨ª â®à ª­®¯ª¨
mov esi,[sc.grab_button] ; 梥⠪­®¯ª¨ RRGGBB
int 0x40
cmp [process.y_size],80
jb .finish
; ᮧ¤ ñ¬ ª­®¯ª¨ ¢ë¡®à  梥â :
mov ebx,10*65536+10 ; ­ ç «ì­ ï x ª®®à¤¨­ â  ¨ à §¬¥à
mov ecx,27*65536+10 ; ­ ç «ì­ ï y ª®®à¤¨­ â  & size
.new_button:
inc edx ; ¨¤¥­â¨ä¨ª â®à++;
mov esi,[btn_colors-8+edx*4] ; 梥⠪­®¯ª¨
int 0x40 ; áâ ¢¨¬ ª­®¯ªã
add ebx,12*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
int 0x40
.finish:
mov eax,12 ; á®®¡é ¥¬ á¨á⥬¥ ® § ¢¥à襭¨¨ ®âà¨á®¢ª¨ ®ª­ 
mov ebx,2
int 0x40
ret
;******************************************************************************
; ­ ç «® ®¡« á⨠¨­¨æ¨ «¨§¨à®¢ ­­ëå ¤ ­­ëå
; ¥á«¨ ªâ® ¥éñ ­¥ §­ ¥â, çâ® §­ ç¨â "¨­¨æ¨ «¨§¨à®¢ ­­ë¥", â® ¯®ïá­ïî:
; í⮠⥠¤ ­­ë¥, ª®â®àë¬ ¯à¨á¢®¥­® ­ ç «ì­®¥ §­ ç¥­¨¥
data
header: ; áâப  § £®«®¢ª 
db 'PAINT v0.2 for MenuetOS'
header_len = $ - header ; ¨ ¥ñ ¤«¨­ 
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>…¨­¨æ¨ «¨§¨à®¢ ­­ëå ¤ ­­ëå, â.¥.
; §¤¥áì ¤ ­­ë¬ §­ ç¥­¨ï ­¥ ¯à¨á¢®¥­ë. ®â«¨ç¨¥ ®â ¨­¨æ., ­¥ 㢥«¨ç¨¢ îâ à §¬¥à
; ä ©« 
udata
active_color dd ? ;  ªâ¨¢­ë© 梥â
old_x dd ? ; áâ àë¥ ª®®à¤¨­ âë ¬ëè¨
old_y dd ?
workarea: ; ª®®à¤¨­ âë ¨ à §¬¥àë ª«¨¥­â᪮© ®¡« áâ¨
.cx dd ? ; c - ª®®¤¨­ âë
.cy dd ?
.sx dd ? ; s - à §¬¥àë
.sy dd ?
sc system_colors ; á¨á⥬­ë¥ 梥â 
process process_information ; ¨­ä®à¬ æ¨ï ® ¯à®æ¥áá¥
restflag dd ?
canvas rb 800*600*3
meos_app_end