Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 108 → Rev 109

/programs/filemngrs/copy2/trunk/copy2.asm
0,0 → 1,427
; project name: SYSTREE FILE COPIER
; version: 1.1b
; last update: 18/07/2004
; compiler: FASM 1.52
; written by: Ivan Poddubny
; e-mail: ivan-yar@bk.ru
; copying-policy: GPL
 
; History:
; 18/07/2004 strings using "lsz" macro + french language (not 100%!)
; 04/06/2004 Bugfix for memory - thanks to Ville
; ...
 
use32
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x20201 ; memory for app
dd 0x10000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
include 'lang.inc'
include 'macros.inc' ; very useful stuff for MeOS
STRLEN = 48 ; maximal length of filename
 
 
START: ; start of execution
 
red:
call draw_window ; at first, draw the window
 
still: ; main cycle of application begins here
 
mov eax,10 ; wait here for event
int 0x40
 
dec eax ; redraw request ?
jz red
dec eax ; key in buffer ?
jz key
dec eax ; button in buffer ?
jz button
 
jmp still
 
key: ; key event handler
mov eax,2 ; just read it and ignore
int 0x40
jmp still ; return to main loop
 
button: ; button
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; button id=1 ? (close_btn)
jz close
 
cmp ah,2 ; copy ?
je copy_file
 
; read_string:
 
cmp ah,5 ; user pressed dest button ?
jz dstbtn
cmp ah,4 ; user pressed src button ?
jnz still
 
srcbtn:
mov [addr],dword source
mov [ya],dword 36
jmp rk
dstbtn:
mov [addr],dword destination
mov [ya],dword 36+16
 
rk:
mov edi,[addr] ; load the address of the string
mov al,0 ; the symbol we will search for
mov ecx,STRLEN+1 ; length of the string (+1)
cld ; search forward
repne scasb ; do search now
inc ecx ; we've found a zero or ecx became 0
mov eax,STRLEN+1
sub eax,ecx ; eax = address of <0> character
mov [temp],eax ; position
 
call print_text
 
mov edi,[addr] ; address of string
add edi,[temp] ; cursor position
 
.waitev:
mov eax,10
int 0x40
cmp eax,2
jnz still
; mov eax,2
int 0x40
shr eax,8
cmp eax,8
jnz .nobs ; BACKSPACE
cmp edi,[addr]
jz .waitev
dec edi
mov [edi],byte 0
call print_text
jmp .waitev
.nobs:
cmp eax,13 ; ENTER
je still
cmp eax,192
jne .noclear
xor al,al
mov edi,[addr]
mov ecx,STRLEN
rep stosb
mov edi,[addr]
call print_text
jmp .waitev
 
.noclear:
mov [edi],al
 
call print_text
 
inc edi
mov esi,[addr]
add esi,STRLEN
cmp esi,edi
jnz .waitev
 
jmp still
 
 
close:
or eax,-1 ; close program
int 0x40
 
 
;====================================================
; copy_file
; This piece of code copies src file to dst file,
; then it pass the control to copy_error routine,
; which returns to the main cycle of the app.
; It's NOT a function! It's reached by direct jump
; from the button handler.
;====================================================
copy_file:
; at first we must get the size of the source file
mov [source_info.blocks],1 ; load only 512 bytes
mov eax,58
mov ebx,source_info
int 0x40
 
; now eax contains error code
; and ebx contains file size in bytes
test eax,eax ; check if eax is equal to zero (success)
je .ok_getsize ; eax = 0 => continue
cmp eax,6
jna @f
mov eax,7 ; if error code is above 6, it will be 7
@@:
cmp eax,5 ; file might be copied successfully altrough
; the system reports an error 5
jne copy_error ; print error code now
.ok_getsize:
 
; allocate memory
push ebx ; save file size
mov ecx,ebx
add ecx,0x20000 ; size of memory needed = 0x20000+filesize
mov eax,64 ; func 64
mov ebx,1 ; resize application memory
int 0x40
pop ebx ; restore filesize
 
; check if alloc function failed
test eax,eax ; non-zero value means error
je .ok_memory
mov eax,5 ; error 5 - out of memory
jmp copy_error ; print error code now
.ok_memory:
 
; save number of blocks to source_info
add ebx,511
shr ebx,9 ; round up to 512 boundary
mov [source_info.blocks],ebx
; read the source file
mov eax,58
mov ebx,source_info
int 0x40
 
; ebx = file size
; save loaded file
mov [dest_info.bytes2write],ebx ; file size in bytes
mov eax,58
mov ebx,dest_info
int 0x40
 
; check if 58 function failed
test eax,eax
je .ok_write
add eax,7 ; error number += 7
cmp eax,6+7
jna copy_error
mov eax,7+7
jmp copy_error
.ok_write:
 
; return to the initial amount of memory
mov eax,64
mov ebx,1
mov ecx,0x20201
int 0x40
 
xor eax,eax ; eax = message number (0-OK)
 
 
; print message now
copy_error:
mov edi,eax
mov eax,4
mov ebx,20*65536+83
mov ecx,0x10ff0000
mov edx,[errors+edi*8]
mov esi,[errors+edi*8+4]
int 0x40
jmp still
 
 
; print strings (source & destination)
print_text:
mov eax,13
mov ebx,107*65536+STRLEN*6
mov ecx,[ya]
shl ecx,16
add ecx,9
mov edx,0xf2f2f2
int 0x40
 
mov eax,4
mov ebx,109*65536
add ebx,[ya]
xor ecx,ecx
mov edx,[addr]
mov esi,STRLEN
int 0x40
 
ret
 
 
; *********************************************
; ******* 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
xor eax, eax ; function 0 : define and draw window
mov ebx, 160*65536+415 ; [x start] *65536 + [x size]
mov ecx, 160*65536+100 ; [y start] *65536 + [y size]
mov edx, 0x03DDDDDD ; color of work area 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, 0x10ffffff ; color of text RRGGBB
mov edx, header ; pointer to text beginning
mov esi, header.size ; text length
int 0x40
 
mov eax, 8 ; COPY BUTTON
mov ebx, 20*65536+375
mov ecx, 63*65536+16
mov edx, 2
mov esi, 0xCCCCCC
int 0x40
 
mov ebx, 105*65536+290
mov ecx, 33*65536+12
mov edx, 4
mov esi, 0xEBEBEB
int 0x40
 
mov ebx, 105*65536+290
mov ecx, 49*65536+12
mov edx, 5
mov esi, 0xEBEBEB
int 0x40
 
mov esi, source
mov edi, text+14
mov ecx, STRLEN
rep movsb
 
mov esi, destination
mov edi, text+STRLEN+59-45+14
mov ecx, STRLEN
rep movsb
 
mov ebx, 25*65536+36 ; print filenames
xor ecx, ecx
mov edx, text
mov esi, STRLEN+59-45
newline:
mov eax, 4
int 0x40
add ebx, 16
add edx, STRLEN+59-45
cmp [edx], byte 'x'
jnz newline
 
mov eax, 12 ; function 12:tell os about windowdraw
mov ebx, 2 ; 2, end of draw
int 0x40
 
ret
 
 
; DATA AREA
align 4
source_info: ; SOURCE FILEINFO
.mode dd 0 ; read file
.start_block dd 0x0 ; block to read
.blocks dd 0x700 ; num of blocks
.address dd 0x20000
.workarea dd 0x10000
source db '/HD/1/KERNEL/KERNEL.MNT',0
times (STRLEN-23) db 0
 
dest_info: ; DESTINATION FILEINFO
.mode dd 1 ; write
.notused dd 0x0 ; not used
.bytes2write dd 0 ; bytes to write
.address dd 0x20000
.workarea dd 0x10000
destination db '/RD/1/KERNEL.MNT',0
times (STRLEN-16) db 0
 
align 4
addr dd 0x0
ya dd 0x0
temp dd 0
 
 
lsz text,\
ru, ' Ž’Š“„€: | ®áá¨ï, Ÿà®á« ¢«ì ',\
ru, ' Š“„€: | ®¤¤ã¡­ë© ˆ¢ ­, ivan-yar@bk.ru ',\
ru, ' ŠŽˆŽ‚€’œ ',\
ru, 'x',\ ; <- END MARKER, DONT DELETE
\
en, 'SOURCE: | Russia, Yaroslavl ',\
en, 'DESTINATION: | Poddubny Ivan, ivan-yar@bk.ru ',\
en, ' COPY SOURCE -> DESTINATION ',\
en, 'x',\ ; <- END MARKER, DONT DELETE
\
fr, 'SOURCE: | ',\
fr, 'DESTINATION: | ',\
fr, ' COPIER ',\
fr, 'x'
 
 
lsz header,\
ru, 'ŠŽˆŽ‚€’œ ”€‰‹',\
en, 'SYSTREE FILE COPIER',\
fr, 'COPIER LE FICHIER'
 
 
;  This macro is used to define a string table in format <pointer;length>
macro strtbl name,[string]
{
common
label name dword
forward
local str,size
dd str,size
forward
str db string
size = $ - str
}
 
if lang eq ru
strtbl errors,\
"ä ©« ᪮¯¨à®¢ ­ ãᯥ譮",\
"(ç⥭¨¥) ­¥ § ¤ ­  ¡ §  ¦¤",\
"(ç⥭¨¥) ä ©«®¢ ï á¨á⥬  ­¥ ¯®¤¤¥à¦¨¢ ¥âáï",\
"(ç⥭¨¥) ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",\
"(ç⥭¨¥) ­¥ § ¤ ­ à §¤¥« ¦¤",\
"­¥¤®áâ â®ç­® ¯ ¬ïâ¨",\
"(ç⥭¨¥) ª®­¥æ ä ©« ",\
"(ç⥭¨¥) ­¥¨§¢¥áâ­ ï ®è¨¡ª ",\
"(§ ¯¨áì) ­¥ § ¤ ­ à §¤¥« ¦¤",\
"(§ ¯¨áì) ä ©«®¢ ï á¨á⥬  ­¥ ¯®¤¤¥à¦¨¢ ¥âáï",\
"(§ ¯¨áì) ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",\
"(§ ¯¨áì) ­¥ § ¤ ­ à §¤¥« ¦¤",\
"?",\
"(§ ¯¨áì) ä ©« ­¥ ­ ©¤¥­",\
"(§ ¯¨áì) ­¥¨§¢¥áâ­ ï ®è¨¡ª "
else
strtbl errors,\
"Success!",\
"(read) no hd base or partition defined",\
"(read) unsupported file system",\
"(read) unknown file system",\
"(read) hd partition not defined",\
"out of memory",\
"(read) end of file",\
"(read) unknown error",\
"(write) no hd base or partition defined",\
"(write) unsupported file system",\
"(write) unknown file system",\
"(write) hd partition not defined",\
"?",\
"(write) end of file",\
"(write) unknown error"
end if
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/filemngrs/copy2/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm copy2.asm copy2
@pause
/programs/filemngrs/copy2/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm copy2.asm copy2
@pause
/programs/filemngrs/copy2/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,b { ; mike.dld
if (~a eq)&(~b eq)
mpack reg,a,b
else if (~a eq)&(b 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
}
 
 
 
 
 
 
; 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