Page 1 of 1

Posted: Fri Dec 02, 2005 7:59 pm
by Wildwest
макросы в начале- из поставки досовского фасм, т.е. файл надо компилить в папке include

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 ,eax ;s <= aІ*(1-2b)+2bІ
;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 ,80000000h
jc positives
mov eax,[x]
lea eax,[2*eax+3]
mul [b2]
add ,eax ;s=s+bІ*(2x+3)

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 ,eax ;s+bІ*(2x+3)

sub eax,[b2] ;+2bІ*(x+1)
add [t],eax

mov eax,[y]
lea eax,[2*eax-2] ;2*(y-1)
mul [a2] ;*aІ
sub ,eax

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 ,eax ;s=s-2*a2*(y-1)
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:

Posted: Sat Dec 03, 2005 12:43 pm
by EXIS
Wildwest
Хороший код... Про рисование круга без SIN/COS я знал (это есть в книге Зубкова), а вот про элипс знал но в реале не видел :)

Posted: Sat Dec 03, 2005 8:11 pm
by Wildwest
Марат, у меня файл fixes.inc выглядит так


_% fix {
%_ fix }

_local_ fix local
_common_ fix common
_forward_ fix forward
_reverse_ fix reverse

Posted: Mon Dec 05, 2005 12:43 pm
by NoName

Posted: Mon Dec 05, 2005 9:21 pm
by Wildwest
; macroinstructions for defining and invoking stdcall HLL procedures

macro proc name,[arg] ; define procedure
{ common
if used name
name:
all@args fix arg
virtual at ebp+8
if ~ arg eq
reverse
first@args fix arg
forward
local ..arg
..arg dd ?
arg equ ..arg
common
end if
..ret = $ - (ebp+8)
end virtual
local ..data,..size
if defined ..size
virtual at ebp - ..size
else
if ..ret
push ebp
mov ebp,esp
end if
end if
..data:
macro enter size,level
_% if size eq & level eq
rb (4 - ($-..data) and 11b) and 11b
if defined ..size
..size = $ - ..data
end virtual
else
..size = $ - ..data
end if
if ..ret | defined ..size
push ebp
mov ebp,esp
if ..size
sub esp,..size
end if
end if
else
enter size,level
end if %_
macro return
_% if ..ret | defined ..size
leave
end if
if ..ret
retn ..ret
else
retn
end if %_ }

macro rstargs [arg]
{ restore arg }

macro endp ; end procedure definition
{ purge return
purge enter
macro rstargs#first@args _% %_
rstargs all@args
purge rstargs#first@args
end if }

macro stdcall proc,[arg] ; call procedure
{ reverse
pushd arg
common
call proc }

macro invoke proc,[arg] ; invoke procedure (indirect)
{ common
if ~ arg eq
reverse
pushd arg
common
call [proc]
else
call [proc]
end if }

Posted: Sun Dec 11, 2005 3:47 pm
by Wildwest
А нахрена вообще использовать stdcall в прогах Колибри?