include 'macro/stdcall.inc'
include 'macro/fixes.inc'
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x100000 ; memory for app
dd 0x7fff0 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
START: ; start of execution
call draw_window
still:
mov eax,10 ; wait here for event
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp still
red: ; redraw
call draw_window
jmp still
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program
int 0x40
noclose:
call draw_window
jmp still
proc drawcircle,x,y,r,c
ox dd ?
oy dd ?
u dd ?
d dd ?
enter
mov ,3
mov [d],5
mov ecx,1 ;h=1-r => ecx
sub ecx,[r] ;x= 0 => eax
mov ebx,[r] ;y= r => ebx
sub [d],ebx
sub [d],ebx
mov [oy],ebx
and eax,0
mov [ox],eax
mov esi,[x]
mov edi,[y]
mov edx,[c]
startcircle:
cmp eax,ebx
ja enddraw
pusha
mov eax,1
mov ebx,esi
mov ecx,edi
mov esi,[ox]
mov edi,[oy]
sub ebx,esi
sub ecx,edi
int 40h
lea ebx,[ebx+2*esi]
int 40h
lea ecx,[ecx+2*edi]
int 40h
sub ebx,esi
sub ebx,esi
int 40h
add ebx,esi
sub ebx,edi
sub ecx,edi
sub ecx,esi
int 40h
lea ebx,[ebx+2*edi]
int 40h
lea ecx,[ecx+2*esi]
int 40h
sub ebx,edi
sub ebx,edi
int 40h
popa
cmp ecx,80000000h
jc selectd
inc eax
inc [ox]
add ecx,
add ,2
add [d],2
jmp startcircle
selectd:
inc eax
inc [ox]
dec ebx
dec [oy]
add ecx,[d]
add ,2
add [d],4
jmp startcircle
enddraw:
return
endp
proc drawellipse,xc,yc,a,b,c
a2 dd ?
b2 dd ?
x dd ?
y dd ?
s dd ?
t dd ?
enter
;s=aІ*(1-2b)+2bІ
mov ecx,1
mov eax,
mov [y],eax ;y=b
lea edx,[2*eax]
sub ecx,edx ;(1-2b)
mul eax ;bІ
mov [b2],eax
mov eax,[a]
mul eax ;aІ
mov [a2],eax
mov [x],0 ;x=0
mul ecx ;aІ*(1-2b)
add eax,[b2] ;+2bІ
add eax,[b2]
mov
;t=bІ-2aІ*(2b-1)
neg ecx ;(2b-1)
mov eax,[a2]
add eax,eax ;2aІ
mul ecx ;*(2b-1)
sub eax,[b2] ;-bІ
neg eax ;-(a-b) == b-a
mov [t],eax ;t=bІ-2aІ*(2b-1)
shl [a2],1 ;2aІ
shl [b2],1 ;2bІ
mov eax,1
mov ebx,[xc]
add ebx,[x]
mov ecx,[yc]
add ecx,[y]
mov edx,[c]
int 40h
sub ebx,[x]
sub ebx,[x]
int 40h
sub ecx,[y]
sub ecx,[y]
int 40h
add ebx,[x]
add ebx,[x]
int 40h
; CALL pixel(xc+x,yc+y,color)
; CALL pixel(xc-x,yc+y,color)
; CALL pixel(xc-x,yc-y,color)
; CALL pixel(xc+x,yc-y,color)
ellipse:
cmp
jc positives
mov eax,[x]
lea eax,[2*eax+3]
mul [b2]
add
sub eax,[b2]
add [t],eax ;t=t+2bІ*(x+1)
inc [x]
jmp startellipse
positives:
cmp [t],80000000h
jc positivet
mov eax,[x] ;s=s+b2*(2*x+3)-2*a2*(y-1)
lea eax,[2*eax+3] ;(2x+3)
mul [b2] ;*bІ
add
sub eax,[b2] ;+2bІ*(x+1)
add [t],eax
mov eax,[y]
lea eax,[2*eax-2] ;2*(y-1)
mul [a2] ;*aІ
sub
sub eax,[a2] ;t=t+2*b2*(x+1)-a2*(2*y-3)
sub [t],eax
inc [x]
dec [y]
jmp startellipse
positivet:
mov eax,[y]
lea eax,[eax*2-2]
mul [a2]
sub
sub eax,[a2]
sub [t],eax ;t=t-a2*(2*y-3)
dec [y]
startellipse:
mov eax,1
mov ebx,[xc]
add ebx,[x]
mov ecx,[yc]
add ecx,[y]
mov edx,[c]
int 40h
sub ebx,[x]
sub ebx,[x]
int 40h
sub ecx,[y]
sub ecx,[y]
int 40h
add ebx,[x]
add ebx,[x]
int 40h
; CALL pixel(xc+x,yc+y,color)
; CALL pixel(xc-x,yc+y,color)
; CALL pixel(xc-x,yc-y,color)
; CALL pixel(xc+x,yc-y,color)
cmp [y],0
jne ellipse
return
endp
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+310 ; [x start] *65536 + [x size]
mov ecx,100*65536+325 ; [y start] *65536 + [y size]
mov edx,0x02ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
; CLOSE BUTTON
mov eax,8 ; function 8 : define and draw button
mov ebx,(300-19)*65536+12 ; [x start] *65536 + [x size]
mov ecx,5*65536+12 ; [y start] *65536 + [y size]
mov edx,1 ; button id
mov esi,0x6688dd ; button color RRGGBB
int 0x40
stdcall drawcircle,155,170,150,255
stdcall drawcircle,(155+1)/2,155/2+170-155,40,0FFFF00h
stdcall drawcircle,155,170,5,000FF00h
stdcall drawcircle,155,170,1,0FF0000h
stdcall drawellipse,200,75,75,25,0
stdcall drawellipse,125,150,25,75,0
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
labelt:
db 'Circle Test Application'
labellen:
I_END: