Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 30 → Rev 31

/programs/xpaint/trunk/ascgl.inc
0,0 → 1,1385
lang equ ru
 
;
; Assembler
; SMALL
; CODE
; Graphics
; Libary
;
; Ver 0.18 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
 
;InfoList
;0.01 LoadImage
;0.02 SetBmp
;0.03 Bmptoimg, Setimg ~01.03.2004
;0.04 Bug deleted, copyimg ~03.05.2004
;0.05 fullimg, collimg ~05.05.2004
;0.06 getimg ~09.05.2004
;0.07 convbmp ~13.05.2004
;0.08 fps ~14.05.2004
;0.09 drawfbox ~03.06.2004
;0.10 all macros optimized by Halyavin A., add at ~07.06.2004
;0.11 many macros optimized by Halyavin A., add at ~30.08.2004
;0.12 bmptoimg ~07.09.2004
;0.13 imgtoimg ~08.09.2004
;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
;0.15 giftoimg, giftoani ~10.09.2004
;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
 
aframetoimg_use_count=0
macro aframetoimg img, x, y, canvas,acol
{
local loo,loo2,acolor
aframetoimg_use_count=aframetoimg_use_count+1
if aframetoimg_use_count = 1
 
jmp end_aframetoimg_proc
 
acolor dd 0
aframetoimg_proc:
;getout coord
mov [acolor],ebp
 
mov edx,ebx ;img ;xsize
movzx eax,word [edx]
add eax,esi ;y cor
 
; mov eax,esi ;y cor
mul dword [ecx] ;canvas xsize
add eax,edi ;x cor
 
mov ebp,ebx ;img ;xsize
movzx edx,word [ebp]
add eax,edx
 
mov ebp,eax
shl eax,1
add ebp,eax
add ebp,ecx ;canvas+8;start
add ebp,8
;get img size
add ebx,4
mov eax,ebx ;img ;xsize
movzx esi,word [eax]
movzx edi,word [eax+2]
add ebx,4
mov edx,ebx ;img+8
loo2:
push esi
loo:
;test on alpha color
mov eax,[edx]
shl eax,8
shr eax,8
cmp eax,[acolor]
jne yx
add edx,3
add ebp,3
jmp nx
yx:
 
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
nx:
dec esi
jnz loo
pop esi
sub ebp,3
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3)
sub eax,esi
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
end_aframetoimg_proc:
end if
push img
push canvas
push x
push y
push acol
pop ebp
pop esi
pop edi
pop ecx
pop ebx
call aframetoimg_proc
}
 
frametoimg_use_count=0
macro frametoimg img, x, y, canvas
{
local loo,loo2
frametoimg_use_count=frametoimg_use_count+1
if frametoimg_use_count = 1
 
jmp end_frametoimg_proc
 
frametoimg_proc:
;getout coord
mov edx,ebx ;img ;xsize
movzx eax,word [edx]
add eax,esi ;y cor
 
; mov eax,esi ;y cor
mul dword [ecx] ;canvas xsize
add eax,edi ;x cor
 
mov ebp,ebx ;img ;xsize
movzx edx,word [ebp]
add eax,edx
 
mov ebp,eax
shl eax,1
add ebp,eax
add ebp,ecx ;canvas+8;start
add ebp,8
;get img size
add ebx,4
mov eax,ebx ;img ;xsize
movzx esi,word [eax]
movzx edi,word [eax+2]
add ebx,4
mov edx,ebx ;img+8
loo2:
push esi
loo:
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
 
dec esi
jnz loo
pop esi
sub ebp,3
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3)
sub eax,esi
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
end_frametoimg_proc:
end if
push img
push canvas
push x
push y
pop esi
pop edi
pop ecx
pop ebx
call frametoimg_proc
}
 
 
aimgtoimg_use_count=0
macro aimgtoimg img, x, y, canvas,acol
{
local loo,loo2,acolor
aimgtoimg_use_count=aimgtoimg_use_count+1
if aimgtoimg_use_count = 1
 
jmp end_aimgtoimg_proc
 
acolor dd 0
aimgtoimg_proc:
;getout coord
mov [acolor],ebp
 
mov eax,esi ;y cor
mul dword [ecx] ;canvas xsize
add eax,edi ;x cor
mov ebp,eax
shl eax,1
add ebp,eax
add ebp,ecx ;canvas+8;start
add ebp,8
;get img size
mov eax,ebx ;img ;xsize
mov esi,[eax]
add ebx,4
mov eax,ebx ; img+4 ;ysize
mov edi,[eax]
add ebx,4
mov edx,ebx ;img+8
loo2:
push esi
loo:
 
;test on alpha color
mov eax,[edx]
shl eax,8
shr eax,8
cmp eax,[acolor]
jne yx
add edx,3
add ebp,3
jmp nx
yx:
 
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
nx:
dec esi
jnz loo
pop esi
sub ebp,3
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3)
sub eax,esi
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
end_aimgtoimg_proc:
end if
push img
push canvas
push x
push y
push acol
pop ebp
pop esi
pop edi
pop ecx
pop ebx
call aimgtoimg_proc
}
 
 
 
 
imgtoimg_use_count=0
macro imgtoimg img, x, y, canvas
{
local loo,loo2
imgtoimg_use_count=imgtoimg_use_count+1
if imgtoimg_use_count = 1
 
jmp end_imgtoimg_proc
imgtoimg_proc:
;getout coord
mov eax,esi ;y cor
mul dword [ecx] ;canvas xsize
add eax,edi ;x cor
mov ebp,eax
shl eax,1
add ebp,eax
add ebp,ecx ;canvas+8;start
add ebp,8
;get img size
mov eax,ebx ;img ;xsize
mov esi,[eax]
add ebx,4
mov eax,ebx ; img+4 ;ysize
mov edi,[eax]
add ebx,4
mov edx,ebx ;img+8
loo2:
push esi
loo:
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
dec esi
jnz loo
pop esi
sub ebp,3
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3)
sub eax,esi
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
end_imgtoimg_proc:
end if
push img
push canvas
push x
push y
pop esi
pop edi
pop ecx
pop ebx
call imgtoimg_proc
}
 
 
;DrawBox
macro drawfbox x,y,xs,ys,color
{
words2reg ebx,x,xs ;x*65536+xs
words2reg ecx,y,ys ;y*65536+ys
mov edx,color
mov eax,13
int 0x40
}
 
; FPS - Set Frame Per Second Display
fps_show_frequency=40
macro fps x,y,color,delcolor
{
local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt
local no_out_fps
jmp spdat
savetime dd 0
fps_cntr dd 0
fps dd 0
ttt dd 0
spdat:
get_time:
mov eax,3
int 0x40
cmp eax,[savetime]
jne new_time
inc [fps_cntr]
cmp dword [ttt],0
je out_fps
dec dword [ttt]
jmp no_out_fps
new_time:
mov [savetime],eax
mov ebx,[fps_cntr]
mov [fps],ebx
mov [fps_cntr],0
out_fps:
if ~(delcolor eq )
mov ebx,x*65536+36
mov ecx,y*65536+7
mov edx,delcolor
mov eax,13
int 0x40
end if
mov dword [ttt],fps_show_frequency
mov eax,47
mov ebx,6*65536
; mov bl,0
mov edx,x*65536+y
mov esi,color
mov ecx,[fps]
int 0x40
no_out_fps:
}
 
; COLLIMG - Collusion image's
_1dbounce_count=0;
macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
{
local bounce,exit,anot,bc,nbc
mov esi,[img1_off] ;xs1
mov edi,[img2_off] ;ys2
mov eax,x1 ;
mov ebx,x2 ;
call _1dbounce
mov edx,ecx
mov esi,[img1_off+4] ;ys1
mov edi,[img2_off+4] ;ys2
mov eax,y1 ;
mov ebx,y2 ;
call _1dbounce
add edx,ecx
cmp edx,2
je bounce
mov otv,0
jmp exit
_1dbounce_count=_1dbounce_count+1
if _1dbounce_count = 1
_1dbounce:
cmp ebx,eax
jb anot
add eax,esi
cmp eax,ebx
jbe nbc
bc:
mov ecx,1
ret
anot:
add ebx,edi
cmp ebx,eax
ja bc
nbc:
xor ecx,ecx
ret
end if
bounce:
mov otv,1
exit:
}
 
macro rgbtobgr image
{
local loo
mov eax,[image]
mul dword [image+4]
mov ecx,eax
mov esi,image+8
; add esi,8
loo:
mov al,[esi]
mov bl,[esi+2]
mov [esi],bl
mov [esi+2],al
add esi,3
dec ecx
jnz loo
}
 
 
macro setimg x , y ,arg3
{
mov eax,7
mov ebx,arg3
add ebx,8
mov cx,[arg3]
shl ecx,16
add cx,[arg3+4]
; wordstoreg ecx,[arg3],[arg3+4]
words2reg edx, x , y ;arg1*65536+arg2
int 0x40
}
 
macro setframe x , y ,arg3
{
mov eax,7
mov ebx,arg3
add ebx,8
words2reg edx, x , y ;arg1*65536+arg2
add edx,dword [arg3]
mov ecx,dword [arg3+4]
int 0x40
}
 
 
macro getimg imgsrc,x,y,xs,ys,imgdest
{
local cyc
if xs eqtype 0
mov dword [imgdest],xs
else
mov eax,xs
mov dword [imgdest],eax
end if
if ys eqtype 0
mov dword [imgdest+4],ys
else
mov eax,ys
mov dword [imgdest+4],eax
end if
 
mov eax,dword [imgsrc] ;getx size
; lea ecx,[eax+2*eax]
mov ecx,eax
shl ecx,1
add ecx,eax
 
mov ebx,y
mul ebx
add eax,x
mov edx,ecx
lea eax,[eax+2*eax] ;eax=offset on imsrc
; mov ebp,eax
; shl eax,1
; add eax,ebp
 
mov ecx,xs
mov ebx,ys
 
mov edi,8+imgdest
lea esi,[eax+8+imgsrc]
; mov esi,eax
; add esi,8
; add esi,imgsrc
 
cld
cyc:
movsw
movsb
dec ecx
jne cyc
add esi,edx
mov ecx,xs
sub esi,ecx
sub esi,ecx
sub esi,ecx
dec ebx
jne cyc
}
 
macro copyimg img2_off,img1_off
{
mov eax,dword [img1_off]
mov ebx,dword [img1_off+4]
mul ebx
lea ecx,[eax+2*eax]
lea esi,[img1_off+8]
lea edi,[img2_off+8]
cld
rep movsb
}
 
macro fullimg img_off,xs,ys,color
{
local cop
mov eax,xs
mov ebx,ys
mov dword [img_off],eax
mov dword [img_off+4],ebx
mul ebx
lea ebp,[eax+2*eax]
mov esi,color
if color eqtype 0
mov ecx,color/65536
else
mov ecx,esi
shr ecx,16
end if
xor edi,edi
cop:
mov word [img_off+8+edi],si
add edi,2
mov byte [img_off+8+edi],cl
inc edi
cmp edi,ebp
jne cop
}
 
 
 
; number of frame in ecx
; callculatin offset of raw data
 
macro getframeoff num_of_frame,offset_of_animation,offset_of_frame
{
local loo,setpic
mov ebp,num_of_frame ;ecx
mov esi,offset_of_animation;Image
loo:
cmp ebp,0
je setpic
movzx eax,word [esi+4]
movzx ebx,word [esi+6]
mul ebx ;dword [esi+4]
mov ebx,3
mul ebx
add eax,8
add esi,eax
dec ebp
jmp loo
setpic:
mov dword offset_of_frame,esi
}
 
 
; BMPTOIMG -Convert BMP format TO IMG format
; (SYNTAX) BMPTOIMG BMP_source_offset,IMG_dest_ofset
; (SAMPLE) View BMPLS.ASM sample.
; ( NOTE ) This is macros is not brake bmp structure! Tested in 32,8,4 bits
 
 
bmptoimg_data_area_count=0
macro bmptoimg bmp_load_area,img_dest_area
{
local fileinfo,string,end_bmp,nodix
local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
;local qwe,bmpfn
 
; convert:
movzx eax,word [bmp_load_area+28]
mul dword [bmp_load_area+18]
add eax,31
shr eax,5
mov dword [bmptoimg_data_area_dwps],eax ;dwps-doublewords per string
shl eax,2
mov dword [bmptoimg_data_area_bps],eax ;bps-bytes per string
 
cmp dword [bmp_load_area+34],0
jne yespicsize ;if picture size is defined
mul dword [bmp_load_area+22]
mov dword [bmp_load_area+34],eax
 
yespicsize:
mov ebp,img_dest_area+8
 
mov eax,bmp_load_area
mov ebx,eax
add ebx, [bmp_load_area+2];file size
inc ebx
mov dword [bmptoimg_soi],ebx ;soi-start of image area for drawing
 
add eax, [bmp_load_area+10]
mov dword [bmptoimg_data_area_sop],eax ;sop-start of picture in file
add eax, [bmp_load_area+34]
mov dword [bmptoimg_data_area_eop],eax ;eop-end of picture in file
mov eax, [bmp_load_area+18]
lea eax,[eax+2*eax] ;3x pixels in eax
 
mov edi,dword [bmptoimg_soi] ;initializing
mov esi,dword [bmptoimg_data_area_eop]
sub esi,dword [bmptoimg_data_area_bps]
 
 
nextstring:
push edi
push ebp
cmp word [bmp_load_area+28],24
jne convertno32
 
mov edi,ebp
mov ecx,[bmptoimg_data_area_dwps]
cld
rep movsd
 
convert1:
pop ebp
pop edi
sub esi,dword [bmptoimg_data_area_bps]
sub esi,dword [bmptoimg_data_area_bps]
cmp esi,dword [bmptoimg_data_area_sop]
jb end_bmp
add edi,eax
add ebp,eax
jmp nextstring
 
convertno32:
mov ebx,bmp_load_area
add ebx, [bmp_load_area+14]
add ebx,14 ;start of color table
push esi
add esi,dword [bmptoimg_data_area_bps]
mov dword [bmptoimg_data_area_eos],esi
pop esi
nextelem:
push eax
movzx eax,byte [esi]
cmp word [bmp_load_area+28],4
je convert4bpp
cmp word [bmp_load_area+28],1
je convert1bpp
call converttable
 
convert2:
pop eax
inc esi
cmp esi,dword [bmptoimg_data_area_eos]
jae convert1
add edi,3
 
add ebp,3
 
jmp nextelem
 
convert4bpp:
shl ax,4
shr al,4
push ax
movzx eax,ah
call converttable
add edi,3
 
add ebp,3
 
pop ax
movzx eax,al
call converttable
jmp convert2
 
convert1bpp:
mov ecx,eax
mov edx,7
nextbit:
xor eax,eax
bt ecx,edx
jnc noaddelem
inc eax
noaddelem:
push edx
call converttable
pop edx
dec edx
js convert2
add edi,3
 
add ebp,3
 
jmp nextbit
 
converttable:
shl eax,2
add eax,ebx
mov edx, dword [eax]
; mov dword [edi],edx
mov [ebp],edx
ret
 
bmptoimg_data_area_count=bmptoimg_data_area_count+1
if bmptoimg_data_area_count = 1
; DATA AREA
bmptoimg_soi dd 0
bmptoimg_data_area_bps dd 0
bmptoimg_data_area_dwps dd 0
bmptoimg_data_area_sop dd 0
bmptoimg_data_area_eop dd 0
bmptoimg_data_area_eos dd 0
end if
 
end_bmp:
mov eax,dword [bmp_load_area+18]
mov ebx,dword [bmp_load_area+22]
mov dword [img_dest_area],eax
mov dword [img_dest_area+4],ebx
}
 
; For convert RGB to BGR
COLOR_ORDER equ MENUETOS
 
macro giftoani gifsrc,imgsrc,num_of_frames
{
local hasharea, ReadGIF, nextblock,_null
local globalColor, img_count, cur_info, img_start
local codesize, compsize, bit_count, CC, EOI, Palette
local block_ofs, table_ptr, gifmacend
local no_gc, block_skip, no_comm, noextblock, uselocal
local setPal, filltable, reinit, cycle, zadd, noinc
local notintable, er, zend, nxt, continue, ex, Gif_skipmap
local Gif_get_sym, shift, nextbl, noblock, loop1, exx
local Gif_output, next, loop2
 
_null equ 0x1000 ; 0x1000
 
; jmp sss
; if defined gif_hash_offset
; else
; hasharea:
; times 4096 dd 0 ;4096
; end if
;sss:
 
mov esi,gifsrc ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
mov edi,imgsrc ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
 
if defined gif_hash_offset
mov eax,gif_hash_offset ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
else
mov eax,hasharea ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
end if
 
call ReadGIF
push ecx
pop dword num_of_frames
jmp gifmacend
 
if defined gif_hash_offset
else
hasharea:
times 4096 dd 0 ;4096
end if
 
ReadGIF:
push esi edi
mov [table_ptr],eax
mov [cur_info],edi
xor eax,eax
mov [globalColor],eax
mov [img_count],eax
inc eax
cmp dword[esi],'GIF8'
jne er ; signature
mov ecx,[esi+0xa]
inc eax
add esi,0xd
mov edi,esi
bt ecx,7
jnc nextblock
mov [globalColor],esi
call Gif_skipmap
nextblock:
cmp byte[edi],0x21
jne noextblock
inc edi
cmp byte[edi],0xf9 ; Graphic Control Ext
jne no_gc
add edi,7
jmp nextblock
no_gc:
cmp byte[edi],0xfe ; Comment Ext
jne no_comm
inc edi
block_skip:
movzx eax,byte[edi]
lea edi,[edi+eax+1]
cmp byte[edi],0
jnz block_skip
inc edi
jmp nextblock
no_comm:
cmp byte[edi],0xff ; Application Ext
jne nextblock
add edi,13
jmp block_skip
noextblock:
cmp byte[edi],0x2c ; image beginning
jne er
inc [img_count]
inc edi
mov esi,[cur_info]
xchg esi,edi
movsd
movsd
 
push edi
movzx ecx,word[esi]
inc esi
bt ecx,7
jc uselocal
push [globalColor]
mov edi,esi
jmp setPal
uselocal:
call Gif_skipmap
push esi
setPal:
movzx ecx,byte[edi]
inc ecx
mov [codesize],ecx
dec ecx
pop [Palette]
lea esi,[edi+1]
mov edi,[table_ptr]
xor eax,eax
cld
lodsb ; eax - block_count
add eax,esi
mov [block_ofs],eax
mov [bit_count],8
mov eax,1
shl eax,cl
mov [CC],eax
inc eax
mov [EOI],eax
lea ecx,[eax-1]
mov eax, _null shl 16
filltable:
stosd
inc eax
loop filltable
pop edi
mov [img_start],edi
reinit:
mov edx,[EOI]
inc edx
push [codesize]
pop [compsize]
call Gif_get_sym
cmp eax,[CC]
je reinit
call Gif_output
cycle:
movzx ebx,ax
call Gif_get_sym
cmp eax,edx
jae notintable
cmp eax,[CC]
je reinit
cmp eax,[EOI]
je zend
call Gif_output
zadd:
push eax
mov eax,[table_ptr]
mov [eax+edx*4],ebx
pop eax
cmp edx,0xFFF
jae cycle
inc edx
bsr ebx,edx
cmp ebx,[compsize]
jne noinc
inc [compsize]
noinc:
jmp cycle
notintable:
push eax
mov eax,ebx
call Gif_output
push ebx
movzx eax,bx
call Gif_output
pop ebx eax
jmp zadd
er:
pop edi
jmp ex
zend:
; mov eax,[.cur_info] ; skip offset to next frame
; mov [eax],edi
mov [cur_info],edi
add esi,2
xchg esi,edi
nxt:
cmp byte[edi],0
jnz continue
inc edi
jmp nxt
continue:
cmp byte[edi],0x3b ;read next frame
jne nextblock
xor eax,eax
stosd
mov ecx,[img_count]
ex:
pop edi esi
ret
 
Gif_skipmap:
; in: ecx - image descriptor, esi - pointer to colormap
; out: edi - pointer to area after colormap
 
and ecx,111b
inc ecx ; color map size
mov ebx,1
shl ebx,cl
lea ebx,[ebx*2+ebx]
lea edi,[esi+ebx]
ret
 
Gif_get_sym:
mov ecx,[compsize]
push ecx
xor eax,eax
shift:
ror byte[esi],1
rcr eax,1
dec [bit_count]
jnz loop1
inc esi
cmp esi,[block_ofs]
jb noblock
push eax
xor eax,eax
lodsb
test eax,eax
jnz nextbl
mov eax,[EOI]
sub esi,2
add esp,8
jmp exx
nextbl:
add eax,esi
mov [block_ofs],eax
pop eax
noblock:
mov [bit_count],8
loop1:
loop shift
pop ecx
rol eax,cl
exx:
xor ecx,ecx
ret
 
Gif_output:
push esi eax edx
mov edx,[table_ptr]
next:
push word[edx+eax*4]
mov ax,word[edx+eax*4+2]
inc ecx
cmp ax,_null
jnz next
shl ebx,16
mov bx,[esp]
loop2:
pop ax
 
lea esi,[eax+eax*2]
add esi,[Palette]
 
if COLOR_ORDER eq MENUETOS
mov esi,[esi]
bswap esi
shr esi,8
mov [edi],esi
add edi,3
else
movsw
movsb
end if
 
loop loop2
pop edx eax esi
ret
 
globalColor dd 1
img_count dd 1
cur_info dd 1 ; image table pointer
img_start dd 1
codesize dd 1
compsize dd 1
bit_count dd 1
CC dd 1
EOI dd 1
Palette dd 1
block_ofs dd 1
table_ptr dd 1
 
gifmacend:
}
 
 
 
macro giftoimg gifsrc,imgsrc
{
local hasharea, ReadGIF, nextblock,_null
local globalColor, img_count, cur_info, img_start
local codesize, compsize, bit_count, CC, EOI, Palette
local block_ofs, table_ptr, gifmacend
local no_gc, block_skip, no_comm, noextblock, uselocal
local setPal, filltable, reinit, cycle, zadd, noinc
local notintable, er, zend, nxt, continue, ex, Gif_skipmap
local Gif_get_sym, shift, nextbl, noblock, loop1, exx
local Gif_output, next, loop2
 
_null equ 0x1000 ; 0x1000
 
mov esi,gifsrc ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
mov edi,imgsrc ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
 
if defined gif_hash_offset
mov eax,gif_hash_offset ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
else
mov eax,hasharea ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
end if
 
call ReadGIF
jmp gifmacend
 
if defined gif_hash_offset
else
hasharea:
times 4096 dd 0 ;4096
end if
 
ReadGIF:
push esi edi
mov [table_ptr],eax
mov [cur_info],edi
xor eax,eax
mov [globalColor],eax
mov [img_count],eax
inc eax
cmp dword[esi],'GIF8'
jne er ; signature
mov ecx,[esi+0xa]
inc eax
add esi,0xd
mov edi,esi
bt ecx,7
jnc nextblock
mov [globalColor],esi
call Gif_skipmap
nextblock:
cmp byte[edi],0x21
jne noextblock
inc edi
cmp byte[edi],0xf9 ; Graphic Control Ext
jne no_gc
add edi,7
jmp nextblock
no_gc:
cmp byte[edi],0xfe ; Comment Ext
jne no_comm
inc edi
block_skip:
movzx eax,byte[edi]
lea edi,[edi+eax+1]
cmp byte[edi],0
jnz block_skip
inc edi
jmp nextblock
no_comm:
cmp byte[edi],0xff ; Application Ext
jne nextblock
add edi,13
jmp block_skip
noextblock:
cmp byte[edi],0x2c ; image beginning
jne er
inc [img_count]
inc edi
mov esi,[cur_info]
xchg esi,edi
; movsd
; movsd
 
mov bp,word[esi+4]
movzx ebx,bp
mov [edi],ebx
 
mov bp,word[esi+6]
movzx ebx,bp
mov [edi+4],ebx
 
add edi,8
add esi,8
 
push edi
movzx ecx,word[esi]
inc esi
bt ecx,7
jc uselocal
push [globalColor]
mov edi,esi
jmp setPal
uselocal:
call Gif_skipmap
push esi
setPal:
movzx ecx,byte[edi]
inc ecx
mov [codesize],ecx
dec ecx
pop [Palette]
lea esi,[edi+1]
mov edi,[table_ptr]
xor eax,eax
cld
lodsb ; eax - block_count
add eax,esi
mov [block_ofs],eax
mov [bit_count],8
mov eax,1
shl eax,cl
mov [CC],eax
inc eax
mov [EOI],eax
lea ecx,[eax-1]
mov eax, _null shl 16
filltable:
stosd
inc eax
loop filltable
pop edi
mov [img_start],edi
reinit:
mov edx,[EOI]
inc edx
push [codesize]
pop [compsize]
call Gif_get_sym
cmp eax,[CC]
je reinit
call Gif_output
cycle:
movzx ebx,ax
call Gif_get_sym
cmp eax,edx
jae notintable
cmp eax,[CC]
je reinit
cmp eax,[EOI]
je zend
call Gif_output
zadd:
push eax
mov eax,[table_ptr]
mov [eax+edx*4],ebx
pop eax
cmp edx,0xFFF
jae cycle
inc edx
bsr ebx,edx
cmp ebx,[compsize]
jne noinc
inc [compsize]
noinc:
jmp cycle
notintable:
push eax
mov eax,ebx
call Gif_output
push ebx
movzx eax,bx
call Gif_output
pop ebx eax
jmp zadd
er:
pop edi
jmp ex
zend:
; mov eax,[.cur_info] ; skip offset to next frame
; mov [eax],edi
mov [cur_info],edi
add esi,2
xchg esi,edi
nxt:
cmp byte[edi],0
jnz continue
inc edi
jmp nxt
continue:
; cmp byte[edi],0x3b ;read next frame
; jne nextblock
xor eax,eax
stosd
mov ecx,[img_count]
ex:
pop edi esi
ret
 
Gif_skipmap:
; in: ecx - image descriptor, esi - pointer to colormap
; out: edi - pointer to area after colormap
 
and ecx,111b
inc ecx ; color map size
mov ebx,1
shl ebx,cl
lea ebx,[ebx*2+ebx]
lea edi,[esi+ebx]
ret
 
Gif_get_sym:
mov ecx,[compsize]
push ecx
xor eax,eax
shift:
ror byte[esi],1
rcr eax,1
dec [bit_count]
jnz loop1
inc esi
cmp esi,[block_ofs]
jb noblock
push eax
xor eax,eax
lodsb
test eax,eax
jnz nextbl
mov eax,[EOI]
sub esi,2
add esp,8
jmp exx
nextbl:
add eax,esi
mov [block_ofs],eax
pop eax
noblock:
mov [bit_count],8
loop1:
loop shift
pop ecx
rol eax,cl
exx:
xor ecx,ecx
ret
 
Gif_output:
push esi eax edx
mov edx,[table_ptr]
next:
push word[edx+eax*4]
mov ax,word[edx+eax*4+2]
inc ecx
cmp ax,_null
jnz next
shl ebx,16
mov bx,[esp]
loop2:
pop ax
 
lea esi,[eax+eax*2]
add esi,[Palette]
 
if COLOR_ORDER eq MENUETOS
mov esi,[esi]
bswap esi
shr esi,8
mov [edi],esi
add edi,3
else
movsw
movsb
end if
 
loop loop2
pop edx eax esi
ret
 
globalColor dd 1
img_count dd 1
cur_info dd 1 ; image table pointer
img_start dd 1
codesize dd 1
compsize dd 1
bit_count dd 1
CC dd 1
EOI dd 1
Palette dd 1
block_ofs dd 1
table_ptr dd 1
 
gifmacend:
}
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/xpaint/trunk/ascgml.inc
0,0 → 1,49
lang equ ru
 
;
; Assembler
; SMALL
; CODE
; GaMe
; Libary
;
; Ver 0.03 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
 
;InfoList
;0.01 correct
;0.02 control ~14.05.2004
;0.03 all macros optimized by halyavin, add at ~07.06.2004
 
 
; corectiryemoe,corectnoe,step
macro correct arg1,arg2,arg3
{
local plus,minus,equal
mov eax,arg2
cmp arg1,eax
je equal
mov eax,arg3
ja minus
plus:
add arg1,eax
jmp equal
minus:
sub arg1,eax
equal:
}
 
macro control min,max,arg
{
local gr,low,norm
mov eax,max
cmp arg,eax
jg gr
mov eax,min
cmp arg,eax
jnl norm
gr:
low:
mov arg,eax
norm:
}
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/xpaint/trunk/ascl.inc
0,0 → 1,897
lang equ ru ; ru en fr ge fi
 
;
; Assembler
; SMALL
; CODE
; Libary
;
; Ver 0.14 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
 
;Please compile aplications on FASM ver1.54 or higer!!!
 
;InfoList
;0.01 scank,putpix,puttxt
;0.02 label,random,colors
;0.03 window,startwd,endwd,attributes
;0.04 close,delay,scevent ~30.04.2004
;0.05 small random, ~04.05.2004
;0.06 wtevent ~09.05.2004
;0.07 timeevent ~23.05.2004
;0.08 txtput ~14.06.2004
;0.09 opendialog,savedialog ~20.06.2004
;0.10 wordstoreg by halyavin, add at ~30.08.2004
; random bug deleted eax is use.
;0.11 loadfile from me +puttxt bug del ~07.09.2004
;0.12 open/save dialog ~13.09.2004
;0.13 dialogs bugs deleted
;0.14 drawlbut ~03.10.2004
;0.15 extendet label!
 
; LOADFILE
; (SYNTAX) LOADFILE 'full_path_to_file',file_load_area,file_temp_area
; (SAMPLE) LOADFILE '/rd/1/clock.bmp',load_area,temp_area
 
 
macro loadfile file_name,file_load_area,file_temp_area
{
local open,fileinfo,string
jmp open
fileinfo:
dd 0
dd 0
dd 1
dd file_load_area
dd file_temp_area
string:
db file_name,0
open:
mov dword [fileinfo+8],1 ; how many blocks to read (1)
mov eax,58
mov ebx,fileinfo
int 0x40
mov eax,[file_load_area+2]
shr eax,9 ; ¯®¤¥«¨¬ ­  512 ¨ ¯à¨¡ ¢¨¬ 1 - ¯®«ã稬 ç¨á«® ¡«®ª®¢
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
int 0x40
}
 
 
;macro wordstoreg reg,hiword,loword
;{
;if hiword eqtype 0 & loword eqtype 0
; mov reg,dword hiword*65536+loword
;else if hiword eqtype 12 & loword eqtype eax
; mov reg,dword hiword*65536
; add reg,dword loword
;else if hiword eqtype 12 & loword eqtype [123]
; mov reg,dword hiword*65536
; add reg,dword loword
;else
; mov reg,dword hiword
; shl reg,16
; add reg,dword loword
;end if
;}
 
macro dword2reg reg,doubleword
{
if doubleword eq
; not changes
else
mov reg,dword doubleword
end if
}
 
macro words2reg reg,hiword,lowword
{
if hiword eq
if lowword eq
; not changes
else
if lowword eqtype 12
and reg,dword 0xffff0000
add reg,dword lowword
else
and reg,dword 0xffff0000
add reg,dword lowword
end if
end if
else
if lowword eq
if hiword eqtype 12
and reg,dword 0x0000ffff
add reg,dword hiword*65536
else
shl reg,16
add reg,dword hiword
ror reg,16
end if
else
if lowword eqtype 12 & hiword eqtype 12
if lowword eq 0 & hiword eq 0
xor reg,reg
else
mov reg,dword hiword*65536+lowword
end if
else
mov reg,dword hiword
shl reg,16
add reg,dword lowword
end if
end if
end if
}
 
 
 
 
; DRAW BUTTON with label
 
macro drawlbut x,y,xs,ys,text,id,bcolor,tcolor
{
local asd,lab
jmp asd
lab db text ;arg label
asd:
words2reg ebx,x,xs
words2reg ecx,y,ys
mov edx,id
mov esi,bcolor
mov eax,8
int 0x40
 
mov eax,asd-lab ;calc size
mov ebx,6
mul ebx
mov esi,eax
 
mov eax,xs
sub eax,esi
shr eax,1
add eax,x
 
mov edx,ys
sub edx,7
shr edx,1
add edx,y
 
mov ebx,eax
shl ebx,16
add ebx,edx
 
mov ecx,tcolor ;arg4 color
mov edx,lab
mov esi,asd-lab ;calc size
mov eax,4
int 0x40
}
 
 
macro opendialog redproc,openoff,erroff,path
{
local new_d, get_loops, dlg_pid_get, DLGPID, num_of_proc
local run_fileinfo, param
local getmesloop, loox, mred, mkey, mbutton, mgetmes
local dlg_is_work, ready, procinfo
;
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
;
 
cld
;; mov esi,path
mov edi,path
mov eax,0
mov ecx,200
rep stosb
 
;mov [get_loops],0
mov [dlg_pid_get],0
 
; Get my PID in dec format 4 bytes
mov eax,9
mov ebx,procinfo
mov ecx,-1
int 0x40
 
; convert eax bin to param dec
mov eax,dword [procinfo+30] ;offset of myPID
mov edi,param+4-1 ;offset to 4 bytes
mov ecx,4
mov ebx,10
cld
new_d:
xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_d
 
; wirite 1 byte space to param
mov [param+4],byte 32 ;Space for next parametr
; and 1 byte type of dialog to param
mov [param+5],byte 'O' ;Get Open dialog (Use 'S' for Save dialog)
 
;
; STEP2 prepare IPC area for get messages
;
 
; prepare IPC area
mov [path],dword 0
mov [path+4],dword 8
 
; define IPC memory
mov eax,60
mov ebx,1 ; define IPC
mov ecx,path ; offset of area
mov edx,150 ; size 150 bytes
int 0x40
 
; change wanted events list 7-bit IPC event
mov eax,40
mov ebx,01000111b
int 0x40
 
;
; STEP 3 run SYSTEM XTREE with parameters
;
 
mov eax,58
mov ebx,run_fileinfo
int 0x40
 
call redproc
 
mov [get_loops],0
getmesloop:
mov eax,23
mov ebx,50 ;0.5 sec
int 0x40
 
cmp eax,1
je mred
cmp eax,2
je mkey
cmp eax,3
je mbutton
cmp eax,7
je mgetmes
 
; Get number of procces
mov ebx,procinfo
mov ecx,-1
mov eax,9
int 0x40
mov ebp,eax
 
loox:
mov eax,9
mov ebx,procinfo
mov ecx,ebp
int 0x40
mov eax,[DLGPID]
cmp [procinfo+30],eax ;IF Dialog find
je dlg_is_work ;jmp to dlg_is_work
dec ebp
jnz loox
 
jmp erroff
 
dlg_is_work:
cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
je erroff ;TESTODP2 terminated too
 
cmp [dlg_pid_get],dword 1
je getmesloop
inc [get_loops]
cmp [get_loops],4 ;2 sec if DLG_PID not get, TESTOP2 terminated
jae erroff
jmp getmesloop
 
mred:
call redproc
jmp getmesloop
mkey:
mov eax,2
int 0x40 ; read (eax=2)
jmp getmesloop
mbutton:
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne getmesloop
mov eax,-1 ; close this program
int 0x40
mgetmes:
 
; If dlg_pid_get then second message get jmp to still
cmp [dlg_pid_get],dword 1
je ready
 
; First message is number of PID SYSXTREE dialog
 
; convert PID dec to PID bin
movzx eax,byte [path+16]
sub eax,48
imul eax,10
movzx ebx,byte [path+16+1]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+2]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+3]
add eax,ebx
sub eax,48
mov [DLGPID],eax
 
; Claear and prepare IPC area for next message
mov [path],dword 0
mov [path+4],dword 8
mov [path+8],dword 0
mov [path+12],dword 0
mov [path+16],dword 0
 
; Set dlg_pid_get for get next message
mov [dlg_pid_get],dword 1
call redproc ;show DLG_PID
jmp getmesloop
 
ready:
;
; The second message get
; Second message is 100 bytes path to SAVE/OPEN file
; shl path string on 16 bytes
;
cld
mov esi,path+16
mov edi,path
mov ecx,200
rep movsb
mov [edi],byte 0
 
jmp openoff
 
 
; DATA AREA
get_loops dd 0
dlg_pid_get dd 0
DLGPID dd 0
 
param:
dd 0 ; My dec PID
dd 0,0 ; Type of dialog
 
run_fileinfo:
dd 16
dd 0
dd param
dd 0
dd procinfo ; 0x10000
;run_filepath
db '/RD/1/SYSXTREE',0
 
procinfo:
times 1024 db 0
}
 
 
macro savedialog redproc,openoff,erroff,path
{
local new_d, get_loops, dlg_pid_get, DLGPID, num_of_proc
local run_fileinfo, run_filepath, param
local getmesloop, loox, mred, mkey, mbutton, mgetmes
local dlg_is_work, ready, procinfo
;
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
;
 
cld
;; mov esi,path
mov edi,path
mov eax,0
mov ecx,200
rep stosb
 
;mov [get_loops],0
mov [dlg_pid_get],0
 
; Get my PID in dec format 4 bytes
mov eax,9
mov ebx,procinfo
mov ecx,-1
int 0x40
 
; convert eax bin to param dec
mov eax,dword [procinfo+30] ;offset of myPID
mov edi,param+4-1 ;offset to 4 bytes
mov ecx,4
mov ebx,10
cld
new_d:
xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_d
 
; wirite 1 byte space to param
mov [param+4],byte 32 ;Space for next parametr
; and 1 byte type of dialog to param
mov [param+5],byte 'S' ;Get Open dialog (Use 'S' for Save dialog)
 
;
; STEP2 prepare IPC area for get messages
;
 
; prepare IPC area
mov [path],dword 0
mov [path+4],dword 8
 
; define IPC memory
mov eax,60
mov ebx,1 ; define IPC
mov ecx,path ; offset of area
mov edx,150 ; size 150 bytes
int 0x40
 
; change wanted events list 7-bit IPC event
mov eax,40
mov ebx,01000111b
int 0x40
 
;
; STEP 3 run SYSTEM XTREE with parameters
;
 
mov eax,58
mov ebx,run_fileinfo
int 0x40
 
call redproc
 
mov [get_loops],0
getmesloop:
mov eax,23
mov ebx,50 ;0.5 sec
int 0x40
 
cmp eax,1
je mred
cmp eax,2
je mkey
cmp eax,3
je mbutton
cmp eax,7
je mgetmes
 
; Get number of procces
mov ebx,procinfo
mov ecx,-1
mov eax,9
int 0x40
mov ebp,eax
 
loox:
mov eax,9
mov ebx,procinfo
mov ecx,ebp
int 0x40
mov eax,[DLGPID]
cmp [procinfo+30],eax ;IF Dialog find
je dlg_is_work ;jmp to dlg_is_work
dec ebp
jnz loox
 
jmp erroff
 
dlg_is_work:
cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
je erroff ;TESTODP2 terminated too
 
cmp [dlg_pid_get],dword 1
je getmesloop
inc [get_loops]
cmp [get_loops],4 ;2 sec if DLG_PID not get, TESTOP2 terminated
jae erroff
jmp getmesloop
 
mred:
call redproc
jmp getmesloop
mkey:
mov eax,2
int 0x40 ; read (eax=2)
jmp getmesloop
mbutton:
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne getmesloop
mov eax,-1 ; close this program
int 0x40
mgetmes:
 
; If dlg_pid_get then second message get jmp to still
cmp [dlg_pid_get],dword 1
je ready
 
; First message is number of PID SYSXTREE dialog
 
; convert PID dec to PID bin
movzx eax,byte [path+16]
sub eax,48
imul eax,10
movzx ebx,byte [path+16+1]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+2]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+3]
add eax,ebx
sub eax,48
mov [DLGPID],eax
 
; Claear and prepare IPC area for next message
mov [path],dword 0
mov [path+4],dword 8
mov [path+8],dword 0
mov [path+12],dword 0
mov [path+16],dword 0
 
; Set dlg_pid_get for get next message
mov [dlg_pid_get],dword 1
call redproc ;show DLG_PID
jmp getmesloop
 
ready:
;
; The second message get
; Second message is 100 bytes path to SAVE/OPEN file
; shl path string on 16 bytes
;
cld
mov esi,path+16
mov edi,path
mov ecx,200
rep movsb
mov [edi],byte 0
 
jmp openoff
 
 
; DATA AREA
get_loops dd 0
dlg_pid_get dd 0
DLGPID dd 0
 
param:
dd 0 ; My dec PID
dd 0,0 ; Type of dialog
 
run_fileinfo:
dd 16
dd 0
dd param
dd 0
dd procinfo
;run_filepath:
db '/RD/1/SYSXTREE',0
 
procinfo:
times 1024 db 0
}
 
 
 
 
; RANDOM - generate random count (small)
; (SYNTAX) RANDOM MaxCount,OutArgument
; (SAMPLE) RANDOM 10000,eax
; ( NOTE ) Maxint<65536 ; use random 65536,eax for more combinations
 
randomuse = 0
 
macro random arg1,arg2
{
local rxproc
randomuse = randomuse + 1
 
jmp rxproc
 
if defined randomuse & randomuse = 1
randomproc:
jmp rnj
rsx1 dw 0x4321
rsx2 dw 0x1234
rnj:
; mov eax,arg1
push bx
push cx
push dx
push si
push di
mov cx,ax
mov ax,word ptr rsx1
mov bx,word ptr rsx2
mov si,ax
mov di,bx
mov dl,ah
mov ah,al
mov al,bh
mov bh,bl
xor bl,bl
rcr dl,1
rcr ax,1
rcr bx,1
add bx,di
adc ax,si
add bx,0x62e9
adc ax,0x3619
mov word ptr rsx1,bx
mov word ptr rsx2,ax
xor dx,dx
cmp ax,0
je nodiv
cmp cx,0
je nodiv
div cx
nodiv:
mov ax,dx
pop di
pop si
pop dx
pop cx
pop bx
and eax,0000ffffh
; mov arg2,0
; mov arg2,eax
ret
end if
 
rxproc:
mov eax,arg1
call randomproc
mov arg2,eax
}
 
macro scank
{
mov eax,10
int 0x40
}
 
macro putpix x,y,color
{
mov ebx,x
mov ecx,y
mov edx,color
mov eax,1
int 0x40
}
 
macro puttxt x,y,offs,size,color
{
; mov ebx,x
; shl ebx,16
; add ebx,y
words2reg ebx,x,y
 
dword2reg ecx,color
dword2reg edx,offs
dword2reg esi,size
 
; mov ecx,color
; mov edx,offs
; mov esi,size
mov eax,4
int 0x40
}
 
macro outcount data, x, y, color, numtype
{
mov ecx,data
mov ebx,numtype
mov bl,0
; mov edx,x*65536+y
words2reg edx,x,y
mov esi,color
mov eax,47
int 0x40
}
 
; SCEVENT - Scan event
 
macro scevent red,key,but
{
mov eax,11
int 0x40
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
; WTEVENT - Wait event
 
macro wtevent red,key,but
{
mov eax,10
int 0x40
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
; TIMEEVENT - Wite for event with timeout
 
macro timeevent xfps,noevent,red,key,but
{
mov eax,23
mov ebx,xfps
int 0x40
cmp eax,0
je noevent
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
 
; CLOSE - Close program
 
macro close
{
mov eax,-1
int 0x40
}
 
; DELAY - Create delay 1/100 sec
; (SYNTAX) Delay time
; (SAMPLE) Delay 100 ;delay 2 sec 1/100*200=2 sec
 
macro delay arg1
{
mov eax,5
mov ebx,arg1
int 0x40
}
 
; WINDOW - Draw window
; (SYNTAX) WINDOW Xstart,Ystart,'Text',Color
; (SAMPLE) WINDOW 10,10,640+8,480+24,window_Skinned
 
macro window arg1,arg2,arg3,arg4,arg5
{
; mov ebx,arg1*65536+arg3
; mov ecx,arg2*65536+arg4
words2reg ebx,arg1,arg3
words2reg ecx,arg2,arg4
mov edx,arg5
mov eax,0
int 0x40
}
 
macro colorwindow arg1,arg2,arg3,arg4,arg5,arg6,arg7
{
mov ebx,arg1*65536+arg3
mov ecx,arg2*65536+arg4
mov edx,arg5
mov esi,arg6
mov edi,arg7
mov eax,0
int 0x40
}
 
 
; STARTWD - Start of window draw
 
macro startwd
{
mov eax,12
mov ebx,1
int 0x40
}
 
; ENDWD - End window draw
 
macro endwd
{
mov eax,12
mov ebx,2
int 0x40
}
 
; LABEL - Put text to frame
; (SYNTAX) LABEL Xstart,Ystart,'Text',Color
; (SAMPLE) LABEL 10,12,'Hello World!',cl_Green+font_Big
 
macro label arg1,arg2,arg3,arg4
{
local asd,lab
jmp asd
lab db arg3 ;arg label
asd:
; mov ebx,arg1 ;arg1=y arg2=x
; shl ebx,16
; add ebx,arg2
 
words2reg ebx,arg1,arg2
 
dword2reg ecx,arg4
 
mov edx,lab
mov esi,asd-lab ;calc size
mov eax,4
int 0x40
}
 
;Key's
key_Up equ 178
key_Down equ 177
key_Right equ 179
key_Left equ 176
key_Esc equ 27
key_Space equ 32
key_Enter equ 13
key_Bspace equ 8
key_F1 equ 50
key_F2 equ 51
key_F3 equ 52
key_F4 equ 53
key_F5 equ 54
key_F6 equ 55
key_F7 equ 56
key_F8 equ 57
key_F9 equ 48
key_F10 equ 49
key_F11 equ 68
key_F12 equ 255
key_Home equ 180
key_End equ 181
key_PgUp equ 184
key_PgDown equ 183
 
;Attributes
 
;Window Attributes
window_Skinned equ 0x03000000
window_Type2 equ 0x02000000
window_Type1 equ 0x00000000
window_Reserve equ 0x01000000
 
;Font Attributes
font_Big equ 0x10000000
 
;Colors
cl_White equ 0x00ffffff
cl_Black equ 0x00000000
cl_Grey equ 0x00888888
cl_Red equ 0x00ff0000
cl_Lime equ 0x0000ff00
cl_Green equ 0x0000af00
cl_Blue equ 0x000000ff
cl_Purple equ 0x008080ff
cl_Violet equ 0x008040ff
cl_Cyan equ 0x0040e0ff
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/xpaint/trunk/ascml.inc
0,0 → 1,93
lang equ ru
 
;
; Assembler
; SMALL
; CODE
; Massive operation
; Libary
;
; Ver 0.1 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
 
;InfoList
;0.01 readmas,compmas,findmas
 
macro readmas masoff,obroff
{
local loo
mov edi,masoff
add edi,8
mov ebp,[masoff] ;elements
mov edx,[masoff+4] ;elemsize
mov eax,0 ;count
loo:
pushad
call obroff
popad
add edi,edx
inc eax
cmp eax,ebp
jne loo
}
 
macro compmas masoff1,masoff2,obroff
{
local loo,loo2
mov esi,masoff2
add esi,8
mov ecx,[masoff2]
mov ebx,[masoff2+4]
mov eax,0
 
loo2:
push eax
 
mov edi,masoff1
add edi,8
mov ebp,[masoff1] ;elements1
mov edx,[masoff1+4] ;elemsize1
mov eax,0 ;count
loo:
pushad
call obroff
popad
add edi,edx
inc eax
cmp eax,ebp
jne loo
 
add esi,ebx
pop eax
inc eax
cmp eax,ecx
jne loo2
}
 
 
macro findmas masoff,obroff
{
local loo,looend,lend
mov edi,masoff
add edi,8
mov ebp,[masoff] ;elements
mov edx,[masoff+4] ;elemsize
mov eax,0 ;count
loo:
pushad
mov eax,0
call obroff
cmp eax,1
je looend
popad
add edi,edx
inc eax
cmp eax,ebp
jne loo
stc
jmp lend
looend:
popad
clc
lend:
}
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/xpaint/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm xpaint.asm xpaint
@pause
/programs/xpaint/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm xpaint.asm xpaint
@pause
/programs/xpaint/trunk/macros.inc
0,0 → 1,266
; new application structure
macro meos_app_start
{
use32
org 0x0
 
db 'MENUET01'
dd 0x01
dd __start
dd __end
dd __memory
dd __stack
 
if used __params & ~defined __params
dd __params
else
dd 0x0
end if
 
dd 0x0
}
MEOS_APP_START fix meos_app_start
 
macro code
{
__start:
}
CODE fix code
 
macro data
{
__data:
}
DATA fix data
 
macro udata
{
if used __params & ~defined __params
__params:
db 0
__end:
rb 255
else
__end:
end if
__udata:
}
UDATA fix udata
 
macro meos_app_end
{
align 32
rb 2048
__stack:
__memory:
}
MEOS_APP_END fix meos_app_end
 
 
; macro for defining multiline text data
struc mstr [sstring]
{
forward
local ssize
virtual at 0
db sstring
ssize = $
end virtual
dd ssize
db sstring
common
dd -1
}
 
 
; strings
macro sz name,[data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if used name
db data
end if
common
if used name
.size = $-name
end if
}
 
macro lsz name,[lng,data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if (used name)&(lang eq lng)
db data
end if
common
if used name
.size = $-name
end if
}
 
 
 
; easy system call macro
macro mpack dest, hsrc, lsrc
{
if (hsrc eqtype 0) & (lsrc eqtype 0)
mov dest, (hsrc) shl 16 + lsrc
else
if (hsrc eqtype 0) & (~lsrc eqtype 0)
mov dest, (hsrc) shl 16
add dest, lsrc
else
mov dest, hsrc
shl dest, 16
add dest, lsrc
end if
end if
}
 
macro __mov reg,a { ; mike.dld
if ~a eq
mov reg,a
end if
}
 
macro mcall a,b,c,d,e,f { ; mike.dld
__mov eax,a
__mov ebx,b
__mov ecx,c
__mov edx,d
__mov esi,e
__mov edi,f
int 0x40
}
 
 
 
; language for programs
lang fix ru ; ru en fr ge fi
 
 
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
macro add arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
inc arg1
else
add arg1,arg2
end if
else
add arg1,arg2
end if
}
 
macro sub arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
dec arg1
else
sub arg1,arg2
end if
else
sub arg1,arg2
end if
}
 
macro mov arg1,arg2
{
if (arg1 in __regs) & (arg2 eqtype 0)
if (arg2) = 0
xor arg1,arg1
else if (arg2) = 1
xor arg1,arg1
inc arg1
else if (arg2) = -1
or arg1,-1
else if (arg2) > -128 & (arg2) < 128
push arg2
pop arg1
else
mov arg1,arg2
end if
else
mov arg1,arg2
end if
}
 
 
macro struct name
{
virtual at 0
name name
sizeof.#name = $ - name
end virtual
}
 
; structures used in MeOS
struc process_information
{
.cpu_usage dd ? ; +0
.window_stack_position dw ? ; +4
.window_stack_value dw ? ; +6
.not_used1 dw ? ; +8
.process_name rb 12 ; +10
.memory_start dd ? ; +22
.used_memory dd ? ; +26
.PID dd ? ; +30
.x_start dd ? ; +34
.y_start dd ? ; +38
.x_size dd ? ; +42
.y_size dd ? ; +46
.slot_state dw ? ; +50
rb (1024-52)
}
struct process_information
 
struc system_colors
{
.frame dd ?
.grab dd ?
.grab_button dd ?
.grab_button_text dd ?
.grab_text dd ?
.work dd ?
.work_button dd ?
.work_button_text dd ?
.work_text dd ?
.work_graph dd ?
}
struct system_colors
 
 
; constants
 
; events
EV_IDLE = 0
EV_TIMER = 0
EV_REDRAW = 1
EV_KEY = 2
EV_BUTTON = 3
EV_EXIT = 4
EV_BACKGROUND = 5
EV_MOUSE = 6
EV_IPC = 7
EV_STACK = 8
 
; event mask bits for function 40
EVM_REDRAW = 1b
EVM_KEY = 10b
EVM_BUTTON = 100b
EVM_EXIT = 1000b
EVM_BACKGROUND = 10000b
EVM_MOUSE = 100000b
EVM_IPC = 1000000b
EVM_STACK = 10000000b
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/xpaint/trunk/xpaint.asm
0,0 → 1,1706
;
; Show Mini Sample by Pavlushin Evgeni for ASCL
; www.waptap@mail.ru
;
 
;bits brushes(right mouse button)!
;resize pucture(cross buttons)!
;Open BMP MIA MHI grafic files!
;Save as MIA MHI(zip from MHC -70% size)!
;Support full files 800*600
;Open and save dialogs is work!
 
; 27Ver Gif load support
; 28Ver Dialogs is work
 
;******************************************************************************
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd IM_END ; size of image
dd I_END ; memory for app
dd I_END ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
;******************************************************************************
include 'lang.inc'
include 'macros.inc'
include 'ascl.inc'
include 'ascgl.inc'
 
hashtable equ MHC_END
ifile equ MHC_END+65536*8 ;4
ofile equ (MHC_END+65536*8)+2000000 ;1000000
 
gif_hash_offset = ofile
 
START: ; start of execution
mov eax,40
mov ebx,0100111b
int 0x40
 
; clear picture color White
mov ecx,1024*768*3
mov eax,0xffffffff
mov edi,image_area
cld
rep stosb
 
call draw_window
call setbrush
 
rstill:
mov eax,37
mov ebx,1
int 0x40
mov ebx,eax
shr eax,16 ;x
and ebx,0xffff ;y
sub eax,5+6
sub ebx,22+30+6
 
cmp eax,640 ;for detect out of screen
ja still
cmp ebx,480
ja still
mov [xt],ebx
mov [yt],eax
 
still:
mov eax,40
mov ebx,0100111b
int 0x40
 
wtevent red,key,button
 
mov ebx,2
mov eax,37
int 0x40
cmp eax,1
je tescor ;if left button not pressed!
cmp eax,2
je cbr ;if right button pressed!
jmp rstill
; jmp still
 
cbr:
cmp dword [brush],9 ;9 brush matrix
jnae nocr
mov [brush],-1 ;0
nocr:
inc [brush]
call setbrush
jmp still
 
;Set brush
setbrush:
mov eax,[brush]
mov ebx,4*32
mul ebx
 
mov ecx,4*32
mov esi,brushtable
add esi,eax
mov edi,matrix
cld
rep movsb
 
delay 10
ret
 
tescor:
mov eax,37
mov ebx,1
int 0x40
mov ebx,eax
shr eax,16 ;x
and ebx,0xffff ;y
 
sub eax,5+6
sub ebx,22+30+6
 
push eax
push ebx
 
mov ecx,eax ;[yt]
mov edx,ebx ;[xt]
 
mov eax,[xt]
mov ebx,[yt]
pop [xt]
pop [yt]
 
call line
 
; mov [yt],eax
; mov [xt],ebx
call out_image
 
jmp still
 
red:
call draw_window
jmp still
 
key: ; key
int 0x40 ; read (eax=2)
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:
cmp ah,10
jb no_palbut
cmp ah,10+32;64
ja no_palbut
mov ecx,0
mov cl,ah
sub cl,10
shl ecx,2
mov ebx,[colortable+ecx]
mov [color],ebx
 
;Update color boxes
drawfbox 20,32,20,15,[backcolor]
drawfbox 12,28,20,15,[color]
 
jmp still
no_palbut:
 
cmp ah,6
jne no_left
 
mov esi,0
mov edi,0
mov ebp,[img_ysize]
x_pls:
mov ecx,0
mov edx,[img_xsize]
x_pl:
mov al,[image_area+edi+ecx]
mov [image_area+esi+ecx],al
mov al,[image_area+edi+ecx+1]
mov [image_area+esi+ecx+1],al
mov al,[image_area+edi+ecx+2]
mov [image_area+esi+ecx+2],al
add ecx,3
dec edx
jnz x_pl
add edi,[img_xsize]
add edi,[img_xsize]
add edi,[img_xsize]
add esi,[img_xsize]
add esi,[img_xsize]
add esi,[img_xsize]
sub esi,3
dec ebp
jns x_pls
 
dec [img_xsize]
jmp red
no_left:
 
 
cmp ah,7
jne no_right
 
mov eax,[img_xsize]
mul [img_ysize]
mov ebx,3
mul ebx
mov edi,eax
 
mov eax,[img_xsize]
inc eax
mul [img_ysize]
mov ebx,3
mul ebx
mov esi,eax
 
; mov esi,0
; mov edi,0
mov ebp,[img_ysize]
x_mns:
mov ecx,[img_xsize] ;0
add ecx,[img_xsize]
add ecx,[img_xsize]
mov edx,[img_xsize]
x_mn:
mov al,[image_area+edi+ecx]
mov [image_area+esi+ecx],al
mov al,[image_area+edi+ecx+1]
mov [image_area+esi+ecx+1],al
mov al,[image_area+edi+ecx+2]
mov [image_area+esi+ecx+2],al
sub ecx,3
dec edx
jnz x_mn
mov dword [image_area+esi+ecx+0],0xffffffff
sub edi,[img_xsize]
sub edi,[img_xsize]
sub edi,[img_xsize]
sub esi,[img_xsize]
sub esi,[img_xsize]
sub esi,[img_xsize]
sub esi,3
dec ebp
jns x_mns
 
inc [img_xsize]
jmp red
no_right:
 
cmp ah,8
jne no_up
dec [img_ysize]
jmp red
no_up:
 
cmp ah,9
jne no_down
inc [img_ysize]
jmp red
no_down:
 
;SAVE MIA
cmp ah,80
jne no_save
savedialog draw_window, mia_is_save, still, string
mia_is_save:
mov dword [fileinfo],1 ;write
mov eax,[img_xsize]
mul [img_ysize]
mov edx,eax
add edx,eax
add edx,eax
add edx,8
cmp edx,1024*768*3+20000
ja still
mov dword [fileinfo+12],image ;from read
mov dword [fileinfo+8],edx ;1
mov eax,58
mov ebx,fileinfo
int 0x40
; puttxt 20,4,string,40,cl_White
jmp still
no_save:
 
;OPEN MIA
cmp ah,81
jne no_open
opendialog draw_window, mia_is_open, still, string
mia_is_open:
mov dword [fileinfo],0 ;read
mov dword [fileinfo+12],image ;from read
mov dword [fileinfo+8],1
mov eax,58
mov ebx,fileinfo
int 0x40
mov eax,ebx
shr eax,9
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
int 0x40
; puttxt 20,4,string,40,cl_White
jmp red
no_open:
 
cmp ah,82
jne no_save_mhc
 
 
savedialog draw_window, mhi_is_save, still, string
mhi_is_save:
call fill_filebufs
mov eax,[img_xsize]
mul [img_ysize]
mov edx,eax
add edx,eax
add edx,eax
add edx,8
mov ecx,edx
mov esi,image
mov edi,ifile
cld
rep movsb
mov eax,edx
call compress
cmp edx,1024*768*3+20000
ja still
mov dword [fileinfo],1 ;write
mov dword [fileinfo+12],ofile ;from read
mov dword [fileinfo+8],edx ;1
mov eax,58
mov ebx,fileinfo
int 0x40
; puttxt 20,4,string,40,cl_White
jmp still
 
no_save_mhc:
 
;OPEN MHI
cmp ah,83
jne no_open_mhc
 
opendialog draw_window, mhi_is_open, still, string
mhi_is_open:
 
call fill_filebufs
 
mov dword [fileinfo],0 ;read
mov dword [fileinfo+12],ofile ;ofile for decompress
mov dword [fileinfo+8],1
mov eax,58
mov ebx,fileinfo
int 0x40
push ebx ;push file size
mov eax,ebx
shr eax,9
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
int 0x40
 
; puttxt 20,4,string,40,cl_White
; delay 100
pop eax ;pop file size
call decompress
 
mov ecx,edx
mov esi,ifile ;image
mov edi,image ;ifile
cld
rep movsb
 
jmp red
no_open_mhc:
 
cmp ah,84
jne no_save_bmp
jmp still
no_save_bmp:
 
cmp ah,85
jne no_open_bmp
 
opendialog draw_window, bmp_is_open, still, string
 
bmp_is_open:
mov dword [fileinfo],0 ;read
mov dword [fileinfo+12],MHC_END ;from read
 
mov dword [fileinfo+8],1
mov eax,58
mov ebx,fileinfo
int 0x40
mov eax,[MHC_END+2]
shr eax,9
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
int 0x40
 
; puttxt 20,4,string,40,cl_White
bmptoimg MHC_END,image
 
jmp red
 
no_open_bmp:
 
 
cmp ah,86
jne no_save_gif
jmp still
no_save_gif:
 
cmp ah,87
jne no_open_gif
 
opendialog draw_window, gif_is_open, still, string
 
gif_is_open:
mov dword [fileinfo],0 ;read
mov dword [fileinfo+12],MHC_END ;from read
 
mov dword [fileinfo+8],1
mov eax,58
mov ebx,fileinfo
int 0x40
mov eax,[MHC_END+2]
shr eax,9
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
int 0x40
 
puttxt 20,4,string,40,cl_White
giftoimg MHC_END,image
 
jmp red
 
no_open_gif:
 
 
 
cmp ah,100
jne nor1
 
mov eax,[img_xsize]
mul [img_ysize]
mov edx,eax
add edx,eax
add edx,eax
mov esi,image+8
norx:
mov al,byte [esi+2]
and al,01b ;10000000b
cmp al,0
jna xe
; mov al,255
mov byte [esi],0;255
mov byte [esi+1],0;0
mov byte [esi+2],255;0
jmp xa
xe:
mov byte [esi],255
mov byte [esi+1],255
mov byte [esi+2],255
xa:
add esi,3
cmp esi,edx
jnae norx
jmp red
nor1:
 
jmp still
 
fileinfo:
dd 0
dd 0
dd 1
dd MHC_END
dd out_image_area ;16384
string:
times 256 db 0
;times 256 db 0
;times 256 db 0
 
;filename db "IMAGE MIA"
;mhcfilename db "IMAGE MHI"
 
soi dd 0
pxs dd 0
pys dd 0
 
out_image:
mov eax,[prcinfo.x_size]
sub eax,21
cmp eax,[img_xsize] ;640
jna no_x
mov eax,[img_xsize] ;640
no_x:
mov [pxs],eax
mov eax,[prcinfo.y_size]
sub eax,68
cmp eax,[img_ysize] ;480
jna no_y
mov eax,[img_ysize] ;480
no_y:
mov [pys],eax
 
mov eax,[pxs]
cmp eax,[img_xsize] ;640
jne trans
mov eax,[pys]
cmp eax,[img_ysize] ;480
jne trans
 
mov eax,7
mov ebx,image_area
mov ecx,[pxs] ;640
shl ecx,16
add ecx,[pys] ;480
mov edx,(5+6)*65536+(22+6+30) ;+30 Reserve for buttons
int 0x40
ret
 
trans:
mov ebp,[pys]; 180
mov esi,image_area
mov edi,out_image_area
loox:
mov ecx,[pxs] ;200*3
add ecx,[pxs]
add ecx,[pxs]
cld
rep movsb
mov eax,[img_xsize] ;640
sub eax,[pxs]
add esi,eax
add esi,eax
add esi,eax
 
dec ebp
jnz loox
 
mov eax,7
mov ebx,out_image_area
mov ecx,[pxs]
shl ecx,16
add ecx,[pys]
 
mov edx,(5+6)*65536+(22+6+30) ;+30 Reserve for buttons
int 0x40
ret
 
 
;set put to massive
puti:
mov eax,edx
mov ebx,ecx
 
setput:
pushad
cmp eax,[img_xsize] ;640
jae nosetput
cmp ebx,[img_ysize] ;480
jae nosetput
mov edi,ebx
mov ebx,3 ;x*3
mul ebx
mov esi,eax
mov eax,[img_xsize] ;640*3 ;Y*640*3
add eax,[img_xsize]
add eax,[img_xsize]
mov ebx,edi
mul ebx
add eax,esi
 
mov ebp,[img_xsize]
shl ebp,4
add ebp,16
mov esi,ebp
add esi,ebp
add esi,ebp
 
sub eax,esi ;(16+640*16)*3
 
mov esi,0
mlix:
push eax
 
mov edi,[matrix+esi*4]
mloo:
shr edi,1
jnc nosp
; cmp eax,640*480*3 ;for detect out of screen
; jae nosp
push eax
mov eax,[img_xsize]
mul [img_ysize]
mov ebx,eax
add ebx,eax
add ebx,eax
pop eax
cmp eax,ebx
jae nosp
 
mov ebx,[color]
mov byte [image_area+eax],bl ;0x00ff
shr ebx,8
mov byte [image_area+eax+1],bl ;0x33
shr ebx,8
mov byte [image_area+eax+2],bl ;0x33
nosp:
add eax,3
cmp edi,0
jne mloo
 
pop eax
add eax,[img_xsize] ;640*3
add eax,[img_xsize]
add eax,[img_xsize]
inc esi
cmp esi,32
jnae mlix
 
nosetput:
popad
ret
 
matrix:
times 32 dd 0
 
brushtable:
;standart put
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
times 12 dd 0
 
;put size 2
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000011000000000000000b
dd 00000000000000011000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
times 12 dd 0
 
;put size 3
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000111000000000000000b
dd 00000000000000111000000000000000b
dd 00000000000000111000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
times 12 dd 0
 
;put size 4
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000111000000000000000b
dd 00000000000001111100000000000000b
dd 00000000000001111100000000000000b
dd 00000000000001111100000000000000b
dd 00000000000000111000000000000000b
dd 00000000000000000000000000000000b
times 12 dd 0
 
 
;put slash ld-ru
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000000010000000000000b
dd 00000000000000000100000000000000b
dd 00000000000000001000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000100000000000000000b
dd 00000000000001000000000000000000b
dd 00000000000010000000000000000000b
times 12 dd 0
 
;put slash lu-rd
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000010000000000000000000b
dd 00000000000001000000000000000000b
dd 00000000000000100000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000001000000000000000b
dd 00000000000000000100000000000000b
dd 00000000000000000010000000000000b
times 12 dd 0
 
;pricel
times 8 dd 0
dd 00000000000000000000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000011111110000000000000b
dd 00000000000010010010000000000000b
dd 00000000000010000010000000000000b
dd 00000000111111010111111000000000b
dd 00000000000010000010000000000000b
dd 00000000000010010010000000000000b
dd 00000000000011111110000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000010000000000000000b
times 8 dd 0
 
;krest
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000010000010000000000000b
dd 00000000000001000100000000000000b
dd 00000000000000101000000000000000b
dd 00000000000000010000000000000000b
dd 00000000000000101000000000000000b
dd 00000000000001000100000000000000b
dd 00000000000010000010000000000000b
times 12 dd 0
 
;krest
times 12 dd 0
dd 00000000000000000000000000000000b
dd 00000000000010000010000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000000000000000000000000b
dd 00000000000010000010000000000000b
times 12 dd 0
 
 
;smile
times 8 dd 0
dd 00000111110000000000000b
dd 00011000001100000000000b
dd 00100000000010000000000b
dd 01000000000001000000000b
dd 01000000000001000000000b
dd 10001100011000100000000b
dd 10001100011000100000000b
dd 10000000000000100000000b
dd 10000000000000100000000b
dd 10010000000100100000000b
dd 01001000001001000000000b
dd 01000111110001000000000b
dd 00100000000010000000000b
dd 00011000001100000000000b
dd 00000111110000000000000b
dd 00000000000000000000000000000000b
times 8 dd 0
 
;round
dd 00000000000111111111100000000000b
dd 00000000011000000000011000000000b
dd 00000001100000000000000110000000b
dd 00000010000000000000000001000000b
dd 00000100000000000000000000100000b
dd 00001000000000000000000000010000b
dd 00010000000000000000000000001000b
dd 00100000000000000000000000000100b
dd 00100000000000000000000000000100b
dd 01000000000000000000000000000010b
dd 01000000000000000000000000000010b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 10000000000000000000000000000001b
dd 01000000000000000000000000000010b
dd 01000000000000000000000000000010b
dd 00100000000000000000000000000100b
dd 00100000000000000000000000000100b
dd 00010000000000000000000000001000b
dd 00001000000000000000000000010000b
dd 00000100000000000000000000100000b
dd 00000010000000000000000001000000b
dd 00000001100000000000000110000000b
dd 00000000011000000000011000000000b
dd 00000000000111111111100000000000b
 
 
;Draw line procedure
line:
jmp n
previous_X dw -1
previous_Y dw -1
X_increment dw -1
Y_increment dw -1
n:
push ax
push bx
push cx
push dx
pop cx ;yed
pop dx ;xed
pop [previous_Y]
pop [previous_X]
 
mov ax,cx
sub ax,[previous_X]
jns dx_pos
neg ax
mov [X_increment],1
jmp dx_neg
dx_pos: mov [X_increment],-1
dx_neg: mov bx,dx
sub bx,[previous_Y]
jns dy_pos
neg bx
mov [Y_increment],1
jmp dy_neg
dy_pos: mov [Y_increment],-1
dy_neg: shl ax,1
shl bx,1
pusha
call puti
popa
cmp ax,bx
jna dx_le_dy
mov di,ax
shr di,1
neg di
add di,bx
cycle:
cmp cx,[previous_X]
je exit_bres
cmp di,0
jl fractlt0
add dx,[Y_increment]
sub di,ax
fractlt0:
add cx,[X_increment]
add di,bx
pusha
call puti
popa
jmp cycle
dx_le_dy:
mov di,bx
shr di,1
neg di
add di,ax
cycle2:
cmp dx,[previous_Y]
je exit_bres
cmp di,0
jl fractlt02
add cx,[X_increment]
sub di,bx
fractlt02:
add dx,[Y_increment]
add di,ax
pusha
call puti
popa
jmp cycle2
exit_bres:
ret
 
 
draw_window:
startwd
window 40,40,(586+8),(380+24),window_Skinned+0x00ffffff
label 12,8,'2D EXAMPLE: ASCL XPAINT',cl_White+font_Big
 
; Get proc info
mov eax,9
mov ebx,prcinfo
mov ecx,-1
int 0x40
 
mov eax,[prcinfo.x_size]
mov ebp,[prcinfo.y_size]
sub eax,5+4
sub ebp,22+4
 
drawfbox 5,22,eax,ebp,0x00e0f0f4
; call out_image
 
; draw resize buttons
mov eax,8
mov ebx,(341)*65536+9
mov ecx,(22+6+6)*65536+6
mov edx,6 ;start with 6
mov esi,0x00aaaaaa
int 0x40
inc edx
add ebx,15*65536
int 0x40
mov ebx,(340+10)*65536+6
mov ecx,(22+6-2)*65536+8
inc edx
mov esi,0x00aaaaaa
int 0x40
inc edx
add ecx,14*65536
int 0x40
 
;Draw now and back color
drawfbox 20,32,20,15,[backcolor]
drawfbox 12,28,20,15,[color]
 
 
;Draw buttons color set
mov eax,8
mov ebx,(40+6)*65536+8
mov ecx,(22+6)*65536+8
mov edx,10 ;start with 10
mov edi,0
nextbut:
mov esi,dword [colorbuttable+edi*4]
int 0x40
add ecx,(10)*65536
inc edx
inc edi
mov esi,dword [colorbuttable+edi*4]
int 0x40
sub ecx,(10)*65536
add ebx,(10)*65536
inc edx
inc edi
cmp edi,32 ;64 buttons, 2 string of 32 buttons
jnae nextbut
 
;Save as not ziped image button
mov eax,8
mov ebx,(365+6)*65536+50
mov ecx,(22+6)*65536+8
mov edx,80 ;ID
mov esi,cl_Grey
int 0x40
 
label (365+7),(22+7),"SAVE MIA",cl_White
 
;Open not zipped image button
mov eax,8
mov ebx,(365+6)*65536+50
mov ecx,(36+6)*65536+8
mov edx,81 ;ID
mov esi,cl_Grey
int 0x40
 
label (365+7),(36+7),"OPEN MIA",cl_White
 
;Save as MHC ziped image button
mov eax,8
mov ebx,(420+6)*65536+50
mov ecx,(22+6)*65536+8
mov edx,82 ;ID
mov esi,cl_Grey
int 0x40
 
label (420+7),(22+7),"SAVE MHI",cl_White
 
;Open MHC zipped image button
mov eax,8
mov ebx,(420+6)*65536+50
mov ecx,(36+6)*65536+8
mov edx,83 ;ID
mov esi,cl_Grey
int 0x40
 
label (420+7),(36+7),"OPEN MHI",cl_White
 
;Save as Bitmap image button
mov eax,8
mov ebx,(475+6)*65536+50
mov ecx,(22+6)*65536+8
mov edx,84 ;ID
mov esi,cl_Grey
int 0x40
 
label (475+7),(22+7),"SAVE NOT",cl_White
 
;Open Bitmap image button
mov eax,8
mov ebx,(475+6)*65536+50
mov ecx,(36+6)*65536+8
mov edx,85 ;ID
mov esi,cl_Grey
int 0x40
 
label (475+7),(36+7),"OPEN BMP",cl_White
 
;Save as GIF image button
mov eax,8
mov ebx,(530+6)*65536+50
mov ecx,(22+6)*65536+8
mov edx,86 ;ID
mov esi,cl_Grey
int 0x40
 
label (530+7),(22+7),"SAVE NOT",cl_White
 
;Open GIF image button
mov eax,8
mov ebx,(530+6)*65536+50
mov ecx,(36+6)*65536+8
mov edx,87 ;ID
mov esi,cl_Grey
int 0x40
 
label (530+7),(36+7),"OPEN GIF",cl_White
 
;Draw filter buttons
mov eax,8
mov ebx,(590+6)*65536+6
mov ecx,(22+6)*65536+6
mov edx,100 ;start with 100
mov edi,0
nextfbut:
mov esi,0x00aa0000
int 0x40
add ecx,(8)*65536
inc edx
inc edi
mov esi,0x0000aa00
int 0x40
add ecx,(8)*65536
inc edx
inc edi
mov esi,0x000000aa
int 0x40
sub ecx,(8*2)*65536
add ebx,(8)*65536
inc edx
inc edi
cmp edi,8*3 ;24 buttons, 3 string of 8 buttons
jnae nextfbut
 
 
endwd
call out_image
ret
 
 
; Get from MHC Archiver by Nikita Lesnikov
; ======== compression/decompression engine ========
 
compress: ; File compression
 
compress_filefound:
 
jmp lzp_compress ; compress with order-2 LZP
compress_dumpdata:
 
ret
 
decompress: ; File decompression
 
decompress_filefound:
 
cmp byte [ofile],0 ; Invalid method!
jz right_method
mov edx,0 ;0 size
ret
 
right_method:
 
jmp lzp_decompress
decompress_dumpdata:
 
ret
 
fill_filebufs: ; Fill filebufs with garbage to simplify matching
pusha
cld
mov eax,0xF7D9A03F ; <- "magic number" :) just garbage...
mov ecx,2000000/2 ;4
mov edi,ifile
rep stosd
popa
ret
 
; ==== algorithms section ====
 
; Method 0: LZP compression algorithm
 
lzp_compress: ; EDX - how much bytes to dump
 
cld ; clear direction flag
 
mov esi,ifile ; init pointers
mov edi,ofile
 
push eax ; write header: ID0+4bfilesize => total 5 bytes
xor eax,eax
stosb
pop eax
stosd
 
pusha ; fill hash table
mov eax,ifile
mov edi,hashtable
mov ecx,65536*2 ;*1
rep stosd
popa
 
add eax,esi ; calculate endpointer
mov dword [endpointer],eax
 
movsw ; copy three bytes
movsb
 
mov dword [controlp],edi
inc edi
 
mov byte [controld],0
mov byte [controlb],0
 
c_loop:
cmp dword [endpointer],esi ; check end of file
ja c_loop_ok
jmp finish_c_loop
c_loop_ok:
 
call chash
call compare
jz two_match_c
 
lodsb
mov byte [literal],al
call chash
call compare
jz lit_match_c
 
mov al,0
call putbit
mov al,byte [literal]
stosb
movsb
jmp end_c_loop
 
lit_match_c:
mov al,1
call putbit
mov al,0
call putbit
mov al,byte [literal]
stosb
jmp encode_match
 
two_match_c:
mov al,1
call putbit
call putbit
 
encode_match:
call incpos
call compare
jz one_c
mov al,0
call putbit
jmp end_c_loop
one_c:
 
call incpos
mov al,1
call putbit
 
call compare
jnz ec1
call incpos
call compare
jnz ec2
call incpos
call compare
jnz ec3
call incpos
mov al,1
call putbit
call putbit
call compare
jnz ec4
call incpos
call compare
jnz ec5
call incpos
call compare
jnz ec6
call incpos
call compare
jnz ec7
call incpos
call compare
jnz ec8
call incpos
call compare
jnz ec9
call incpos
call compare
jnz ec10
call incpos
 
mov al,1
call putbit
call putbit
call putbit
xor ecx,ecx
 
match_loop_c:
cmp esi,dword [endpointer]
jae out_match_loop_c
call compare
jnz out_match_loop_c
inc ecx
call incpos
jmp match_loop_c
out_match_loop_c:
 
mov al,0xFF
out_lg:
cmp ecx,255
jb out_lg_out
stosb
sub ecx,255
jmp out_lg
out_lg_out:
mov al,cl
stosb
jmp end_c_loop
 
ec10:
mov al,1
call putbit
call putbit
mov al,0
call putbit
jmp end_c_loop
 
ec9:
mov al,1
call putbit
mov al,0
call putbit
mov al,1
call putbit
jmp end_c_loop
 
ec8:
mov al,1
call putbit
mov al,0
call putbit
call putbit
jmp end_c_loop
 
ec7:
mov al,0
call putbit
mov al,1
call putbit
call putbit
jmp end_c_loop
 
ec6:
mov al,0
call putbit
mov al,1
call putbit
mov al,0
call putbit
jmp end_c_loop
 
ec5:
mov al,0
call putbit
call putbit
mov al,1
call putbit
jmp end_c_loop
 
ec4:
mov al,0
call putbit
call putbit
call putbit
jmp end_c_loop
 
ec3:
mov al,1
call putbit
mov al,0
call putbit
jmp end_c_loop
 
ec2:
mov al,0
call putbit
mov al,1
call putbit
jmp end_c_loop
 
ec1:
mov al,0
call putbit
call putbit
 
end_c_loop:
jmp c_loop
 
finish_c_loop:
 
mov eax,dword [controlp] ; store last tagbyte
mov bl,byte [controld]
mov [eax], byte bl
 
sub edi,ofile ; calculate dump size
mov edx,edi
 
jmp compress_dumpdata
 
; LZP decompression algorithm
 
lzp_decompress: ; EDX - how much bytes to dump
 
cld
 
mov edi,ifile
mov esi,ofile+1
 
pusha ; fill hash table
mov eax,ifile
mov edi,hashtable
mov ecx,65536*2 ;*1
rep stosd
popa
 
lodsd
 
mov ebx,edi
add ebx,eax
mov dword [endpointer],ebx
 
movsw
movsb
 
lodsb
mov byte [controld],al
mov byte [controlb],0
 
d_loop:
cmp dword [endpointer],edi
ja d_loop_ok
jmp finish_d_loop
d_loop_ok:
 
call getbit
cmp al,0
jnz match_d
call dhash
movsb
call dhash
movsb
jmp end_d_loop
 
match_d:
 
call getbit
cmp al,0
jnz no_literal_before_match
call dhash
movsb
no_literal_before_match:
 
call dhash
mov ecx,1
call copymatch
 
call getbit
cmp al,0
jz end_d_loop
mov ecx,1
call copymatch
call getbit
cmp al,0
jz dc2
mov ecx,2
call copymatch
call getbit
cmp al,0
jz end_d_loop
mov ecx,1
call copymatch
call getbit
cmp al,0
jz dc4
mov ecx,4
call copymatch
call getbit
cmp al,0
jz dc5
call getbit
cmp al,0
jz dc6
mov ecx,3
call copymatch
 
do:
lodsb
xor ecx,ecx
mov cl,al
call copymatch
cmp al,0xFF
jnz end_do
jmp do
end_do:
jmp end_d_loop
 
dc6:
mov ecx,2
call copymatch
jmp end_d_loop
 
dc5:
call getbit
cmp al,0
jz ndc5
mov ecx,1
call copymatch
ndc5:
jmp end_d_loop
 
dc4:
call getbit
cmp al,0
jz ndc4
call getbit
mov ecx,3
cmp al,1
jz ndcc4
dec ecx
ndcc4:
call copymatch
jmp end_d_loop
ndc4:
call getbit
cmp al,0
jz ndccc4
mov ecx,1
call copymatch
ndccc4:
jmp end_d_loop
 
dc2:
call getbit
cmp al,0
jz ndc2
mov ecx,1
call copymatch
ndc2:
 
end_d_loop:
jmp d_loop
finish_d_loop:
 
mov edx, dword [ofile+1]
 
jmp decompress_dumpdata
 
; LZP subroutines
 
putbit: ; bit -> byte tag, AL holds bit for output
pusha
mov cl,byte [controlb]
shl al,cl
mov bl,byte [controld]
or bl,al
mov byte [controld],bl
inc cl
cmp cl,8
jnz just_increment
mov byte [controlb],0
mov byte [controld],0
push edi
mov edi, dword [controlp]
mov al,bl
stosb
pop edi
mov dword [controlp],edi
popa
inc edi
ret
just_increment:
mov byte [controlb],cl
popa
ret
 
getbit: ; tag byte -> bit, AL holds input
push ecx
mov al,byte [controld]
mov cl,byte [controlb]
shr al,cl
and al,1
inc cl
cmp cl,8
jnz just_increment_d
mov byte [controlb],0
push eax
lodsb
mov byte [controld],al
pop eax
pop ecx
ret
just_increment_d:
mov byte [controlb],cl
pop ecx
ret
 
chash: ; calculate hash -> mp -> fill position
pusha
xor eax,eax
mov al, byte [esi-1]
mov ah, byte [esi-2]
shl eax,2
add eax,hashtable
mov edx,dword [eax]
mov dword [mp],edx
mov dword [eax],esi
popa
ret
 
dhash: ; calculate hash -> mp -> fill position
pusha
xor eax,eax
mov al, byte [edi-1]
mov ah, byte [edi-2]
shl eax,2
add eax,hashtable
mov edx,dword [eax]
mov dword [mp],edx
mov dword [eax],edi
popa
ret
 
copymatch: ; ECX bytes from [mp] to [rp]
push esi
mov esi,dword [mp]
rep movsb
mov dword [mp],esi
pop esi
ret
 
compare: ; compare [mp] with [cpos]
push edi
push esi
mov edi,dword [mp]
cmpsb
pop esi
pop edi
ret
 
incpos:
inc dword [mp]
inc esi
ret
 
 
; LZP algorithm data
 
endpointer dd 0
controlp dd 0
controlb db 0
controld db 0
mp dd 0
literal db 0
 
; the end... - Nikita Lesnikov (nlo_one)
 
 
 
; DATA AREA
newline dd 0
xt dd 100
yt dd 100
counter dd 0
tsoi dd 0
view dd 0
brush dd 0
 
color dd 0x00000000
backcolor dd 0xffffff
 
colortable:
dd 0x00000000 ;black
dd 0x00FFFFFF ;white
dd 0x00808080 ;dark-gray
dd 0x00C0C0C0 ;gray
dd 0x00000080 ;dark-blue
dd 0x000000ff ;blue
dd 0x00400080 ;dark-violet
dd 0x008000ff ;violet
dd 0x00800080 ;dark-pink
dd 0x00ff00ff ;pink
dd 0x00800040 ;
dd 0x00ff0080 ;
dd 0x00800000 ;brown
dd 0x00ff0000 ;red
dd 0x00802000 ;
dd 0x00ff4000 ;dark-orange
dd 0x00804000 ;
dd 0x00ff8000 ;orange
dd 0x00804000 ;
dd 0x00ff8000 ;orange
dd 0x00808000 ;oliva
dd 0x00ffff00 ;yellow
dd 0x00608000 ;
dd 0x00C0ff00 ;
dd 0x00408000 ;green
dd 0x0080ff00 ;lime
dd 0x00008000 ;
dd 0x0000ff00 ;
dd 0x00008040 ;dark-salat
dd 0x0000ff80 ;salat
dd 0x00008080 ;dark-water
dd 0x0000ffff ;water
 
colorbuttable:
dd 0x001e1e1e ;black
dd 0x00dedede ;white
dd 0x00808080 ;dark-gray
dd 0x00C0C0C0 ;gray
dd 0x001e1e80 ;dark-blue
dd 0x001e1ede ;blue
dd 0x00401e80 ;dark-violet
dd 0x00801ede ;violet
dd 0x00801e80 ;dark-pink
dd 0x00de1ede ;pink
dd 0x00801e40 ;
dd 0x00de1e80 ;
dd 0x00801e1e ;brown
dd 0x00de1e1e ;red
dd 0x0080201e ;
dd 0x00de401e ;dark-orange
dd 0x0080401e ;
dd 0x00de801e ;orange
dd 0x0080401e ;
dd 0x00de801e ;orange
dd 0x0080801e ;oliva
dd 0x00dede1e ;yellow
dd 0x0060801e ;
dd 0x00C0de1e ;
dd 0x0040801e ;green
dd 0x0080de1e ;lime
dd 0x001e801e ;
dd 0x001ede1e ;
dd 0x001e8040 ;dark-salat
dd 0x001ede80 ;salat
dd 0x00008080 ;dark-water
dd 0x0000dede ;water
 
 
 
prcinfo process_information
 
;IM_END:
image:
img_xsize dd 200
img_ysize dd 180
IM_END:
image_area:
;rb 1024*768*3
 
out_image_area = image_area+(1024*768*3)
;rb 640*480*3
 
MHC_END = image_area+(1024*768*3)*2
I_END = MHC_END+6000000 ;6 megs for work mhc algorythm
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property