diff --git a/data/Tupfile.lua b/data/Tupfile.lua index 8d4f56698..aaee66781 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -154,7 +154,7 @@ extra_files = { {"kolibrios/3D/info3ds/INFO3DS.INI", SRC_PROGS .. "/develop/info3ds/info3ds.ini"}, {"kolibrios/3D/info3ds/OBJECTS.PNG", SRC_PROGS .. "/develop/info3ds/objects.png"}, {"kolibrios/3D/info3ds/TOOLBAR.PNG", SRC_PROGS .. "/develop/info3ds/toolbar.png"}, - {"kolibrios/3D/info3ds/FONT8X9.BMP", SRC_PROGS .. "/fs/kfar/trunk/font8x9.bmp"}, + {"kolibrios/3D/info3ds/FONT8X9.BMP", SRC_PROGS .. "/fs/kfar/font8x9.bmp"}, {"kolibrios/3D/blocks/blocks.kex", "../programs/bcc32/games/blocks/bin/blocks.kex"}, {"kolibrios/3D/blocks/models/", "../programs/bcc32/games/blocks/models/*"}, {"kolibrios/3D/md2view/", "common/3d/md2view/*"}, @@ -164,7 +164,7 @@ extra_files = { {"kolibrios/3D/voxel_editor/HOUSE2.VOX", SRC_PROGS .. "/media/voxel_editor/trunk/house2.vox"}, {"kolibrios/3D/voxel_editor/SQUIRREL.VOX", SRC_PROGS .. "/media/voxel_editor/trunk/squirrel.vox"}, {"kolibrios/3D/voxel_utilites/VOX_MOVER.INI" , SRC_PROGS .. "/media/voxel_editor/utilites/vox_mover.ini"}, - {"kolibrios/3D/FONT8X9.BMP", SRC_PROGS .. "/fs/kfar/trunk/font8x9.bmp"}, + {"kolibrios/3D/FONT8X9.BMP", SRC_PROGS .. "/fs/kfar/font8x9.bmp"}, {"kolibrios/3D/TOOLB_1.PNG", SRC_PROGS .. "/develop/libraries/TinyGL/asm_fork/examples/toolb_1.png"}, {"kolibrios/3D/TEST_GLU1", VAR_PROGS .. "/develop/libraries/TinyGL/asm_fork/examples/test_glu1"}, {"kolibrios/3D/TEST_GLU2", VAR_PROGS .. "/develop/libraries/TinyGL/asm_fork/examples/test_glu2"}, @@ -486,7 +486,7 @@ tup.append_table(img_files, { {"DEVELOP/EXAMPLES/CONGET", VAR_PROGS .. "/develop/libraries/console_coff/examples/test_gets"}, {"DEVELOP/EXAMPLES/CSLIDE", VAR_PROGS .. "/demos/cslide/trunk/cslide"}, {"DEVELOP/EXAMPLES/THREAD", VAR_PROGS .. "/develop/examples/thread/trunk/thread"}, - {"File Managers/KFAR", VAR_PROGS .. "/fs/kfar/trunk/kfar"}, + {"File Managers/KFAR", VAR_PROGS .. "/fs/kfar/kfar"}, {"File Managers/OPENDIAL", VAR_PROGS .. "/fs/opendial/opendial"}, {"LOD", VAR_PROGS .. "/fs/lod/lod"}, {"GAMES/15", VAR_PROGS .. "/games/15/15"}, @@ -505,7 +505,7 @@ tup.append_table(img_files, { {"GAMES/TANKS", VAR_PROGS .. "/games/tanks/tanks"}, {"GAMES/TETRIS", VAR_PROGS .. "/games/tetris/tetris"}, {"GAMES/C4", VAR_PROGS .. "/games/c4/c4"}, - {"LIB/ARCHIVER.OBJ", VAR_PROGS .. "/fs/kfar/trunk/kfar_arc/kfar_arc.obj"}, + {"LIB/ARCHIVER.OBJ", VAR_PROGS .. "/fs/kfar/kfar_arc/kfar_arc.obj"}, {"LIB/BOX_LIB.OBJ", VAR_PROGS .. "/develop/libraries/box_lib/trunk/box_lib.obj"}, {"LIB/BUF2D.OBJ", VAR_PROGS .. "/develop/libraries/buf2d/trunk/buf2d.obj"}, {"LIB/CONSOLE.OBJ", VAR_PROGS .. "/develop/libraries/console_coff/console.obj"}, diff --git a/programs/build_all.bat b/programs/build_all.bat index 65338383e..5621f5aa0 100644 --- a/programs/build_all.bat +++ b/programs/build_all.bat @@ -113,7 +113,7 @@ echo Building fs echo * fasm fs\copy2\trunk\copy2.asm %BIN%\copy2 fasm fs\copyr\copyr.asm %BIN%\copyr -fasm fs\kfar\trunk\kfar.asm %BIN%\kfar +fasm fs\kfar\kfar.asm %BIN%\kfar rem fasm fs\mfar\trunk\mfar.asm %BIN%\mfar fasm fs\sysxtree\trunk\sysxtree.asm %BIN%\sysxtree diff --git a/programs/develop/info3ds/build_en.bat b/programs/develop/info3ds/build_en.bat index d2f53d285..69adc5dd6 100644 --- a/programs/develop/info3ds/build_en.bat +++ b/programs/develop/info3ds/build_en.bat @@ -4,7 +4,7 @@ if not exist bin mkdir bin @copy objects.png bin\objects.png if not exist bin\info3ds.ini @copy info3ds.ini bin\info3ds.ini if not exist bin\toolbar.png @copy toolbar.png bin\toolbar.png -if not exist bin\font8x9.bmp @copy ..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @fasm.exe -m 16384 info3ds.asm bin\info3ds.kex @kpack bin\info3ds.kex @fasm.exe -m 16384 info3ds_u.asm bin\info3ds_u.kex diff --git a/programs/develop/info3ds/build_ru.bat b/programs/develop/info3ds/build_ru.bat index 278cbf03a..313fb6c4c 100644 --- a/programs/develop/info3ds/build_ru.bat +++ b/programs/develop/info3ds/build_ru.bat @@ -4,7 +4,7 @@ if not exist bin mkdir bin @copy objects.png bin\objects.png if not exist bin\info3ds.ini @copy info3ds.ini bin\info3ds.ini if not exist bin\toolbar.png @copy toolbar.png bin\toolbar.png -if not exist bin\font8x9.bmp @copy ..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @fasm.exe -m 16384 info3ds.asm bin\info3ds.kex @kpack bin\info3ds.kex @fasm.exe -m 16384 info3ds_u.asm bin\info3ds_u.kex diff --git a/programs/develop/kol_f_edit/build.bat b/programs/develop/kol_f_edit/build.bat index b95ac89ea..77369f1c8 100644 --- a/programs/develop/kol_f_edit/build.bat +++ b/programs/develop/kol_f_edit/build.bat @@ -8,8 +8,8 @@ if not exist bin\icon.bmp @copy icon.bmp bin\icon.bmp if not exist bin\base.bmp @copy base.bmp bin\base.bmp if not exist bin\left.bmp @copy left.bmp bin\left.bmp if not exist bin\oper.bmp @copy oper.bmp bin\oper.bmp -if not exist bin\font6x9.bmp @copy ..\..\fs\kfar\trunk\font6x9.bmp bin\font6x9.bmp +if not exist bin\font6x9.bmp @copy ..\..\fs\kfar\font6x9.bmp bin\font6x9.bmp if not exist bin\asm.syn @copy ..\..\other\t_edit\info\asm.syn bin\asm.syn copy *.ced bin\*.ced -pause \ No newline at end of file +pause diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/build.bat b/programs/develop/libraries/TinyGL/asm_fork/examples/build.bat index 4a68e69a3..fbddc2c97 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/examples/build.bat +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/build.bat @@ -1,6 +1,6 @@ if not exist bin mkdir bin @copy *.png bin\*.png -if not exist bin\font8x9.bmp @copy ..\..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\..\..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp if not exist bin\tinygl.obj @fasm.exe -m 16384 ..\tinygl.asm bin\tinygl.obj @fasm.exe -m 16384 test0.asm bin\test0.kex @@ -38,4 +38,4 @@ if not exist bin\tinygl.obj @fasm.exe -m 16384 ..\tinygl.asm bin\tinygl.obj @kpack bin\textures1.kex @kpack bin\textures2.kex -pause \ No newline at end of file +pause diff --git a/programs/develop/libraries/buf2d/trunk/examples/build.bat b/programs/develop/libraries/buf2d/trunk/examples/build.bat index 0c091ab97..d96a21fb6 100644 --- a/programs/develop/libraries/buf2d/trunk/examples/build.bat +++ b/programs/develop/libraries/buf2d/trunk/examples/build.bat @@ -1,6 +1,6 @@ if not exist bin mkdir bin -if not exist bin\font8x9.bmp @copy ..\..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\..\..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @copy foto.jpg bin\foto.jpg @copy img0.png bin\img0.png @copy img1.png bin\img1.png @@ -25,4 +25,4 @@ if not exist bin\vaz2106.vox @copy ..\..\..\..\..\media\voxel_editor\trunk\vaz21 @kpack bin\e6_vox_1g.kex @kpack bin\e7_vox_3g.kex @kpack bin\e8_filters.kex -pause \ No newline at end of file +pause diff --git a/programs/develop/libraries/crypt_des/example/build.bat b/programs/develop/libraries/crypt_des/example/build.bat index 8098727d8..4b66e3aa5 100644 --- a/programs/develop/libraries/crypt_des/example/build.bat +++ b/programs/develop/libraries/crypt_des/example/build.bat @@ -2,7 +2,7 @@ if not exist bin mkdir bin @fasm.exe -m 16384 crypt_files.asm bin\crypt_files.kex @kpack bin\crypt_files.kex if not exist bin\toolbar.png @copy toolbar.png bin\toolbar.png -if not exist bin\font8x9.bmp @copy ..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @fasm.exe -m 16384 ..\trunk\crypt_des.asm bin\crypt_des.obj @kpack bin\crypt_des.obj -pause \ No newline at end of file +pause diff --git a/programs/develop/libraries/exif/examples/build.bat b/programs/develop/libraries/exif/examples/build.bat index dd945c02c..7a031437b 100644 --- a/programs/develop/libraries/exif/examples/build.bat +++ b/programs/develop/libraries/exif/examples/build.bat @@ -2,7 +2,7 @@ if not exist bin mkdir bin @fasm.exe -m 16384 viev_exif.asm bin\viev_exif.kex @kpack bin\viev_exif.kex if not exist bin\toolbar.png @copy toolbar.png bin\toolbar.png -if not exist bin\font8x9.bmp @copy ..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @fasm.exe -m 16384 ..\trunk\exif.asm bin\exif.obj @kpack bin\exif.obj -pause \ No newline at end of file +pause diff --git a/programs/develop/libraries/libs-dev/libimg/png/libpng/png.asm b/programs/develop/libraries/libs-dev/libimg/png/libpng/png.asm index 9976c29bf..b582f5863 100644 --- a/programs/develop/libraries/libs-dev/libimg/png/libpng/png.asm +++ b/programs/develop/libraries/libs-dev/libimg/png/libpng/png.asm @@ -1,4 +1,3 @@ - ; png.asm - location for general purpose libpng functions ; Last changed in libpng 1.6.25 [September 1, 2016] @@ -13,7 +12,7 @@ DEBUG equ 0 include '../../../../../../KOSfuncs.inc' -include '../../../../../../fs/kfar/trunk/zlib/deflate.inc' +include '../../../../../../fs/kfar/zlib/deflate.inc' include 'pngtokos.inc' ;integrate png to kos ;files from libpng diff --git a/programs/develop/libraries/libs-dev/libimg/png/libpng/pngstruct.inc b/programs/develop/libraries/libs-dev/libimg/png/libpng/pngstruct.inc index 95771d022..a8a0d556e 100644 --- a/programs/develop/libraries/libs-dev/libimg/png/libpng/pngstruct.inc +++ b/programs/develop/libraries/libs-dev/libimg/png/libpng/pngstruct.inc @@ -21,7 +21,7 @@ ; in this structure and is required for decompressing the LZ compressed ; data in PNG files. -include '../../../../../../fs/kfar/trunk/zlib/zlib.inc' +include '../../../../../../fs/kfar/zlib/zlib.inc' ; zlib.inc declares a magic type 'uInt' that limits the amount of data that zlib ; can handle at once. This type need be no larger than 16 bits (so maximum of @@ -74,7 +74,7 @@ ends ; from chromaticities the sum of the Y values is assumed to be 1.0 struct png_XYZ - red_X dd ? ;png_fixed_point + red_X dd ? ;png_fixed_point red_Y dd ? red_Z dd ? green_X dd ? diff --git a/programs/fs/kfar/trunk/Tupfile.lua b/programs/fs/kfar/Tupfile.lua similarity index 79% rename from programs/fs/kfar/trunk/Tupfile.lua rename to programs/fs/kfar/Tupfile.lua index 7c3d9c33c..031939bd0 100644 --- a/programs/fs/kfar/trunk/Tupfile.lua +++ b/programs/fs/kfar/Tupfile.lua @@ -1,5 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end -HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") add_include(tup.getvariantdir()) diff --git a/programs/fs/kfar/trunk/api.txt b/programs/fs/kfar/api.txt similarity index 100% rename from programs/fs/kfar/trunk/api.txt rename to programs/fs/kfar/api.txt diff --git a/programs/fs/kfar/trunk/build_en.bat b/programs/fs/kfar/build_en.bat similarity index 100% rename from programs/fs/kfar/trunk/build_en.bat rename to programs/fs/kfar/build_en.bat diff --git a/programs/fs/kfar/trunk/build_ru.bat b/programs/fs/kfar/build_ru.bat similarity index 100% rename from programs/fs/kfar/trunk/build_ru.bat rename to programs/fs/kfar/build_ru.bat diff --git a/programs/fs/kfar/trunk/dialogs.inc b/programs/fs/kfar/dialogs.inc similarity index 100% rename from programs/fs/kfar/trunk/dialogs.inc rename to programs/fs/kfar/dialogs.inc diff --git a/programs/fs/kfar/trunk/editor.inc b/programs/fs/kfar/editor.inc similarity index 100% rename from programs/fs/kfar/trunk/editor.inc rename to programs/fs/kfar/editor.inc diff --git a/programs/fs/kfar/trunk/filetool.inc b/programs/fs/kfar/filetool.inc similarity index 100% rename from programs/fs/kfar/trunk/filetool.inc rename to programs/fs/kfar/filetool.inc diff --git a/programs/fs/kfar/trunk/font.inc b/programs/fs/kfar/font.inc similarity index 100% rename from programs/fs/kfar/trunk/font.inc rename to programs/fs/kfar/font.inc diff --git a/programs/fs/kfar/trunk/font10x20.bmp b/programs/fs/kfar/font10x20.bmp similarity index 100% rename from programs/fs/kfar/trunk/font10x20.bmp rename to programs/fs/kfar/font10x20.bmp diff --git a/programs/fs/kfar/trunk/font6x9.bmp b/programs/fs/kfar/font6x9.bmp similarity index 100% rename from programs/fs/kfar/trunk/font6x9.bmp rename to programs/fs/kfar/font6x9.bmp diff --git a/programs/fs/kfar/trunk/font7x12.bmp b/programs/fs/kfar/font7x12.bmp similarity index 100% rename from programs/fs/kfar/trunk/font7x12.bmp rename to programs/fs/kfar/font7x12.bmp diff --git a/programs/fs/kfar/trunk/font8x16.bmp b/programs/fs/kfar/font8x16.bmp similarity index 100% rename from programs/fs/kfar/trunk/font8x16.bmp rename to programs/fs/kfar/font8x16.bmp diff --git a/programs/fs/kfar/trunk/font8x9.bmp b/programs/fs/kfar/font8x9.bmp similarity index 100% rename from programs/fs/kfar/trunk/font8x9.bmp rename to programs/fs/kfar/font8x9.bmp diff --git a/programs/fs/kfar/trunk/kfar.asm b/programs/fs/kfar/kfar.asm similarity index 99% rename from programs/fs/kfar/trunk/kfar.asm rename to programs/fs/kfar/kfar.asm index 9caf0db73..2571c16d5 100644 --- a/programs/fs/kfar/trunk/kfar.asm +++ b/programs/fs/kfar/kfar.asm @@ -1,3 +1,9 @@ +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + + use32 db 'MENUET01' dd 1 @@ -15,8 +21,8 @@ max_width = 255 min_height = 8 max_height = 255 -include '../../../KOSfuncs.inc' -include '../../../macros.inc' +include '../../KOSfuncs.inc' +include '../../macros.inc' include 'lang.inc' ; Language support for locales: ru_RU (CP866), en_US. include 'font.inc' include 'sort.inc' diff --git a/programs/fs/kfar/trunk/kfar.ini b/programs/fs/kfar/kfar.ini similarity index 100% rename from programs/fs/kfar/trunk/kfar.ini rename to programs/fs/kfar/kfar.ini diff --git a/programs/fs/kfar/trunk/kfar.txt b/programs/fs/kfar/kfar.txt similarity index 100% rename from programs/fs/kfar/trunk/kfar.txt rename to programs/fs/kfar/kfar.txt diff --git a/programs/fs/kfar/trunk/kfar_arc/7z.inc b/programs/fs/kfar/kfar_arc/7z.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/7z.inc rename to programs/fs/kfar/kfar_arc/7z.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/7zaes.inc b/programs/fs/kfar/kfar_arc/7zaes.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/7zaes.inc rename to programs/fs/kfar/kfar_arc/7zaes.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/7zbranch.inc b/programs/fs/kfar/kfar_arc/7zbranch.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/7zbranch.inc rename to programs/fs/kfar/kfar_arc/7zbranch.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/Tupfile.lua b/programs/fs/kfar/kfar_arc/Tupfile.lua similarity index 79% rename from programs/fs/kfar/trunk/kfar_arc/Tupfile.lua rename to programs/fs/kfar/kfar_arc/Tupfile.lua index 104d3e93d..4bcdfd8bd 100644 --- a/programs/fs/kfar/trunk/kfar_arc/Tupfile.lua +++ b/programs/fs/kfar/kfar_arc/Tupfile.lua @@ -1,5 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end -HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") add_include(tup.getvariantdir()) diff --git a/programs/fs/kfar/trunk/kfar_arc/aes.inc b/programs/fs/kfar/kfar_arc/aes.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/aes.inc rename to programs/fs/kfar/kfar_arc/aes.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/archiver_deflate.txt b/programs/fs/kfar/kfar_arc/archiver_deflate.txt similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/archiver_deflate.txt rename to programs/fs/kfar/kfar_arc/archiver_deflate.txt diff --git a/programs/fs/kfar/trunk/kfar_arc/crc.inc b/programs/fs/kfar/kfar_arc/crc.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/crc.inc rename to programs/fs/kfar/kfar_arc/crc.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/deflate.inc b/programs/fs/kfar/kfar_arc/deflate.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/deflate.inc rename to programs/fs/kfar/kfar_arc/deflate.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/kfar_arc.asm b/programs/fs/kfar/kfar_arc/kfar_arc.asm similarity index 95% rename from programs/fs/kfar/trunk/kfar_arc/kfar_arc.asm rename to programs/fs/kfar/kfar_arc/kfar_arc.asm index 8afc43e0c..059cb579e 100644 --- a/programs/fs/kfar/trunk/kfar_arc/kfar_arc.asm +++ b/programs/fs/kfar/kfar_arc/kfar_arc.asm @@ -1,1579 +1,1584 @@ -; -; project name: KFar_Arc - plugin for KFar, which supports various archives -; target platform: KolibriOS -; compiler: FASM 1.67.14 -; version: 0.17 -; last update: 2016-11-04 (Nov 04, 2016) -; minimal KFar version: 0.43 -; minimal kernel: no limit -; -; author: Diamond -; email: diamondz@land.ru -; web: http://diamond.kolibrios.org -; - -; standard start of Kolibri dynamic library -format MS COFF -public EXPORTS - -section '.flat' code readable align 16 - -; include auxiliary procedures -include 'kglobals.inc' ; iglobal/uglobal -include 'lang.inc' ; define language for localized strings -include 'crc.inc' ; CRC32 calculation -include 'sha256.inc' ; SHA-256 hash algorithm -include 'aes.inc' ; AES crypto algorithm -; include main code for archives loading -include '7z.inc' ; *.7z -include 'lzma.inc' ; LZMA-decoder for *.7z -include 'ppmd.inc' ; PPMD-decoder for *.7z -include '7zbranch.inc' ; branch filters for *.7z -include '7zaes.inc' ; AES cryptor for *.7z -include 'zip.inc' ; *.zip -include 'deflate.inc' ; Deflate[64] decoder for *.7z and *.zip -include '../zlib/zlib.asm' ; deflate coder - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;; Interface for KFar ;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -virtual at 0 -kfar_info_struc: -.lStructSize dd ? -.kfar_ver dd ? -.open dd ? -.open2 dd ? -.read dd ? -.write dd ? -.seek dd ? -.tell dd ? -.flush dd ? -.filesize dd ? -.close dd ? -.pgalloc dd ? -.pgrealloc dd ? -.pgfree dd ? -.getfreemem dd ? -.pgalloc2 dd ? -.pgrealloc2 dd ? -.pgfree2 dd ? -.menu dd ? -.menu_centered_in dd ? -.DialogBox dd ? -.SayErr dd ? -.Message dd ? -.cur_console_size dd ? -end virtual - -; int __stdcall plugin_load(kfar_info* info); -; Initialization of plugin + Save used KFar functions. -plugin_load: - mov eax, [esp+4] - mov [kfar_info], eax - push [eax+kfar_info_struc.open2] - pop [open2] - push [eax+kfar_info_struc.filesize] - pop [filesize] - push [eax+kfar_info_struc.read] - pop [read] - push [eax+kfar_info_struc.seek] - pop [seek] - push [eax+kfar_info_struc.close] - pop [close] - lea esi, [eax+kfar_info_struc.DialogBox] - mov edi, DialogBox - movsd - movsd - movsd - movsd - lea esi, [eax+kfar_info_struc.pgalloc] - mov edi, pgalloc - movsd - movsd - movsd - movsd - call init_crc_table - call init_aes - call init_ppmd - xor eax, eax ; success - ret 4 - -; HANDLE __stdcall OpenFilePlugin(HANDLE basefile, -; const void* attr, const void* data, int datasize, -; int baseplugin_id, HANDLE baseplugin_instance, const char* name); -; This function is called when user presses Enter (or Ctrl+PgDn) on file. -; Plugin tests whether given file is of supported type -; and if so, loads information and returns -; handle to be used in subsequent calls to ReadFolder, SetFolder and so on. -OpenFilePlugin: - mov [bPasswordDefined], 0 - mov esi, [esp+12] - mov ebp, [esp+4] -; test for 7z archive - cmp dword [esp+16], 20h ; minimal size of 7z archive is 20h bytes - jb .no_7z - cmp word [esi], '7z' ; signature, part 1 - jnz .no_7z - cmp dword [esi+2], 0x1C27AFBC ; signature, part 2 - jnz .no_7z - call open_7z - ret 28 -.no_7z: -; test for zip archive - cmp dword [esp+16], 22 ; minimal size of zip archive is 22 bytes - jb .no_zip - cmp word [esi], 0x4B50 - jnz .no_zip - cmp word [esi+2], 0x0403 - jz .zip - cmp word [esi+2], 0x0201 - jz .zip - cmp word [esi+2], 0x0606 - jz .zip - cmp word [esi+2], 0x0706 - jz .zip - cmp word [esi+2], 0x0605 - jnz .no_zip -.zip: - call open_zip - ret 28 -.no_zip: - xor eax, eax - ret 28 - -; Handle of plugin in kfar_arc is as follow: -virtual at 0 -handle_common: -.type dd ? -.root.subfolders dd ? -.root.subfolders.end dd ? -.root.subfiles dd ? -.root.subfiles.end dd ? -.root.NumSubItems dd ? -.curdir dd ? -.NumFiles dd ? -; ... some plugin-specific data follows ... -end virtual - -; and for each archive item there is one file info structure, which begins as follow: -virtual at 0 -file_common: -.fullname dd ? ; pointer to cp866 string -.name dd ? ; name without path (end of .fullname) -.namelen dd ? ; strlen(.name) -.bIsDirectory db ? -.bPseudoFolder db ? - rb 2 -.parent dd ? ; pointer to parent directory record -.subfolders dd ? ; head of L2-list of subfolders [for folders] -.subfolders.end dd ? -.subfiles dd ? ; head of L2-list of files [for folders] -.subfiles.end dd ? -.NumSubItems dd ? -.next dd ? ; next item in list of subfolders/files -.prev dd ? ; previous item in list of subfolders/files -.stamp dd ? ; stamp for GetFiles -end virtual - -; void __stdcall ClosePlugin(HANDLE hPlugin); -; This function frees all resources allocated in OpenFilePlugin. -ClosePlugin: - mov eax, [esp+4] ; get hPlugin - mov eax, [eax] ; hPlugin is pointer to internal data structure - ; first dword is archive type (type_xxx constants) - dec eax ; types start from 1 - jmp dword [ClosePluginTable+eax*4] - -; int __stdcall ReadFolder(HANDLE hPlugin, -; unsigned dirinfo_start, unsigned dirinfo_size, void* dirdata); -ReadFolder: -; init header - mov edi, [esp+16] - mov ecx, 32/4 - xor eax, eax - rep stosd - mov byte [edi-32], 1 ; version - mov ebp, [esp+4] -; get current directory - lea ebx, [ebp+handle_common.root.subfolders] - cmp [ebp+handle_common.curdir], 0 - jz @f - mov ebx, [ebp+handle_common.curdir] - add ebx, file_common.subfolders -@@: - mov ecx, [ebx+16] - mov [edi-24], ecx ; number of files -; edi points to BDFE - push 6 ; assume EOF - pop eax - sub ecx, [esp+8] - ja @f - and dword [edi-28], 0 ; number of files read - ret 10h -@@: - cmp ecx, [esp+12] - jb @f - mov ecx, [esp+12] - xor eax, eax ; OK -@@: - mov [edi-28], ecx - push eax -; copy files data - jecxz .done -; seek to required item - mov eax, [esp+8+4] - mov esi, [ebx] -.0: - test esi, esi - jnz .1 - mov esi, [ebx+8] -.1: - add esi, ebp - dec eax - js .2 - mov esi, [esi+file_common.next] - jmp .0 -.2: -.copy: - pushad - mov eax, esi - mov ecx, [ebp] - call dword [getattrTable+(ecx-1)*4] - pop edi esi - push esi edi - add edi, 40 - mov ecx, [esi+file_common.namelen] - mov esi, [esi+file_common.name] - rep movsb - mov byte [edi], 0 - popad - add edi, 304 - mov esi, [esi+file_common.next] - test esi, esi - jnz @f - mov esi, [ebx+8] -@@: - add esi, ebp - loop .copy -.done: - pop eax - ret 10h - -; bool __stdcall SetFolder(HANDLE hPlugin, -; const char* relative_path, const char* absolute_path); -SetFolder: - mov ebp, [esp+4] - mov edx, [ebp+handle_common.curdir] - mov esi, [esp+8] - cmp dword [esi], '..' - jz .toparent - xor ecx, ecx -@@: - inc ecx - cmp byte [esi+ecx], 0 - jnz @b - mov ebx, [ebp+handle_common.root.subfolders] - test edx, edx - jz .scan - mov ebx, [edx+file_common.subfolders] -.scan: - test ebx, ebx - jz .err - add ebx, ebp - cmp [ebx+file_common.namelen], ecx - jnz .cont - push ecx esi - mov edi, [ebx+file_common.name] - repz cmpsb - pop esi ecx - jz .set -.cont: - mov ebx, [ebx+file_common.next] - jmp .scan -.toparent: - test edx, edx - jz .err - mov ebx, [edx+file_common.parent] - test ebx, ebx - jz @f - add ebx, ebp -@@: -.set: - mov [ebp+handle_common.curdir], ebx - mov al, 1 - ret 12 -.err: - xor eax, eax - ret 12 - -iglobal -cur_stamp dd 0 -endg - -uglobal -tmp_bdfe rb 304 -endg - -; void __stdcall GetFiles(HANDLE hPlugin, int NumItems, void* items[], -; void* addfile, void* adddir); -; bool __stdcall addfile(const char* name, void* bdfe_info, HANDLE hFile); -; bool __stdcall adddir(const char* name, void* bdfe_info); -GetFiles: - mov ebp, [esp+4] - mov ecx, [ebp+handle_common.NumFiles] - test ecx, ecx - jz .ret - mov ebx, ebp - mov eax, [ebx] - add ebx, [basesizes+(eax-1)*8] - inc [cur_stamp] -.loop: - push ecx - mov esi, [ebx+file_common.fullname] - mov edx, [ebp+handle_common.curdir] - test edx, edx - jz .incur - mov eax, [cur_stamp] - mov [edx+file_common.stamp], eax - mov edi, [edx+file_common.fullname] - mov ecx, [edx+file_common.namelen] - add ecx, [edx+file_common.name] - sub ecx, edi - repz cmpsb - jnz .cont -.incur: - cmp byte [esi], '/' - jnz @f - inc esi -@@: - mov ecx, [esp+12] ; NumItems - mov edx, [esp+16] ; items - cmp ecx, -1 - jz .ok -.check: - sub ecx, 1 - js .cont - push esi - mov edi, [edx] - add edi, 40 -@@: - lodsb - scasb - jnz @f - test al, al - jz .ok2 - jmp @b -@@: - pop esi - cmp al, '/' - jnz @f - cmp byte [edi-1], 0 - jz .ok -@@: - add edx, 4 - jmp .check -.ok2: - pop esi -.ok: -; add all parents directories if needed -.parloope: - mov ecx, [ebx+file_common.parent] - jecxz .pardone - add ecx, ebp - mov eax, [cur_stamp] - cmp [ecx+file_common.stamp], eax - jz .pardone -.parloopi: - mov edx, ecx - mov ecx, [ecx+file_common.parent] - jecxz @f - add ecx, ebp - cmp [ecx+file_common.stamp], eax - jnz .parloopi -@@: - mov [edx+file_common.stamp], eax - push esi - mov ecx, [edx+file_common.name] - add ecx, [edx+file_common.namelen] - xor eax, eax - xchg al, [ecx] - push eax ecx - mov eax, edx - mov edi, tmp_bdfe - push edi - sub esi, [ebx+file_common.fullname] - add esi, [edx+file_common.fullname] - push esi - mov ecx, [ebp] - call dword [getattrTable+(ecx-1)*4] - mov eax, [esp+24+20] - call eax - pop ecx edx - mov [ecx], dl - pop esi - test al, al - jz .forced_exit - jmp .parloope -.pardone: - cmp [ebx+file_common.bIsDirectory], 0 - jz .addfile - mov eax, [cur_stamp] - cmp [ebx+file_common.stamp], eax - jz .cont - mov [ebx+file_common.stamp], eax - push esi - mov ecx, [ebx+file_common.name] - add ecx, [ebx+file_common.namelen] - xor eax, eax - xchg al, [ecx] - push eax ecx - mov eax, ebx - mov edi, tmp_bdfe - push edi - push esi - mov ecx, [ebp] - call dword [getattrTable+(ecx-1)*4] - mov eax, [esp+24+20] - call eax - pop ecx edx - mov [ecx], dl - pop esi - test al, al - jz .forced_exit - jmp .cont -.addfile: - push ebx esi ebp - push 11h - pop edi - mov eax, ebx - mov ecx, [ebp] - call dword [openTable+(ecx-1)*4] - pop ebp esi ebx - test eax, eax - jz .cont - push eax - push eax - mov edi, tmp_bdfe - push edi - push esi - mov eax, ebx - mov ecx, [ebp] - call dword [getattrTable+(ecx-1)*4] - mov eax, [esp+20+16] - call eax - pop ecx - push eax ebp - push ebx - push ecx - call myclose - pop ebx - pop ebp eax - test al, al - jz .forced_exit -.cont: - mov eax, [ebp] - add ebx, [basesizes+(eax-1)*8+4] - pop ecx - dec ecx - jnz .loop -.ret: - ret 20 -.forced_exit: - pop ecx - jmp .ret - -; void __stdcall GetOpenPluginInfo(HANDLE hPlugin, OpenPluginInfo* info); -GetOpenPluginInfo: - mov eax, [esp+8] ; get info ptr - mov byte [eax], 3 ; flags: add non-existing '..' entry automatically - ; use GetFiles for copying - ret 8 - -; int __stdcall getattr(HANDLE hPlugin, const char* filename, void* info); -mygetattr: - call lookup_file_name - test eax, eax - jz @f - mov edx, [ebp] - dec edx - mov edi, [esp+12] ; info ptr - call dword [getattrTable+edx*4] - xor eax, eax - ret 12 -@@: - mov al, 5 ; ERROR_FILE_NOT_FOUND - ret 12 - -; HANDLE __stdcall open(HANDLE hPlugin, const char* filename, int mode); -myopen: - call lookup_file_name - test eax, eax - jz @f - mov edx, [ebp] - dec edx - mov edi, [esp+12] ; mode - call dword [openTable+edx*4] -@@: - ret 12 - -; unsigned __stdcall read(HANDLE hFile, void* buf, unsigned size); -myread: - mov ebx, [esp+4] - mov eax, [ebx] - jmp dword [readTable+eax*4] - -; void __stdcall setpos(HANDLE hFile, __int64 pos); -mysetpos: - mov ebx, [esp+4] - mov eax, [ebx] - jmp dword [setposTable+eax*4] - -; void __stdcall close(HANDLE hFile); -myclose: - mov ebx, [esp+4] - mov eax, [ebx] - jmp dword [closeTable+eax*4] - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;; Auxiliary procedures ;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -; return.err and return.clear are labels to jmp if something is invalid -; the caller must previously define [_esp], [_ebp] and [error_proc], [clear_proc] -return.err: - mov esp, [_esp] - mov ebp, [_ebp] - jmp [error_proc] -return.clear: - mov esp, [_esp] - mov ebp, [_ebp] - jmp [clear_proc] - -; data for following routine -iglobal -align 4 -_24 dd 24 -_60 dd 60 -_10000000 dd 10000000 -days400year dd 365*400+100-4+1 -days100year dd 365*100+25-1 -days4year dd 365*4+1 -days1year dd 365 -months dd 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 -months2 dd 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 -_400 dd 400 -_100 dd 100 -endg - -; Convert QWORD FILETIME to BDFE format. -ntfs_datetime_to_bdfe: -; edx:eax = number of 100-nanosecond intervals since January 1, 1601, in UTC - push eax - mov eax, edx - xor edx, edx - div [_10000000] - xchg eax, [esp] - div [_10000000] - pop edx -; edx:eax = number of seconds since January 1, 1601 - push eax - mov eax, edx - xor edx, edx - div [_60] - xchg eax, [esp] - div [_60] - mov [edi], dl - pop edx -; edx:eax = number of minutes - div [_60] - mov [edi+1], dl -; eax = number of hours (note that 2^64/(10^7*60*60) < 2^32) - xor edx, edx - div [_24] - mov [edi+2], dl - mov [edi+3], byte 0 -; eax = number of days since January 1, 1601 - xor edx, edx - div [days400year] - imul eax, 400 - add eax, 1601 - mov [edi+6], ax - mov eax, edx - xor edx, edx - div [days100year] - cmp al, 4 - jnz @f - dec eax - add edx, [days100year] -@@: - imul eax, 100 - add [edi+6], ax - mov eax, edx - xor edx, edx - div [days4year] - shl eax, 2 - add [edi+6], ax - mov eax, edx - xor edx, edx - div [days1year] - cmp al, 4 - jnz @f - dec eax - add edx, [days1year] -@@: - add [edi+6], ax - push esi edx - mov esi, months - movzx eax, word [edi+6] - test al, 3 - jnz .noleap - xor edx, edx - push eax - div [_400] - pop eax - test edx, edx - jz .leap - xor edx, edx - div [_100] - test edx, edx - jz .noleap -.leap: - mov esi, months2 -.noleap: - pop edx - xor eax, eax - inc eax -@@: - sub edx, [esi] - jb @f - add esi, 4 - inc eax - jmp @b -@@: - add edx, [esi] - pop esi - inc edx - mov [edi+4], dl - mov [edi+5], al - add edi, 8 - ret - -; By given array of files information, initialize links between them -; ("[folder] contains [item]" relations). -; Information structure must be compatible with 'file_common'. -; Size of information structure is in [esp+4]. -init_file_links: -; in: edx->file infos, ebx = number of files, [esp+4] = size, -; edi->{dd root.subfolders, dd root.subfolders.end, -; dd root.subfiles, dd root.subfiles.end, dd root.NumItems} - xor eax, eax - mov [.free], eax - push edi - stosd - stosd - stosd - stosd - stosd - pop edi -; Loop through all files -.mainloop: - dec ebx - js .mainloopdone -; Parse file name -; esi->current character in name -; dword [esp] = start of current component in file name -; ecx->{dd curdir.subfolders, dd curdir.subfolders.end, -; dd curdir.subfiles, dd curdir.subfiles.end} - mov esi, [edx+file_common.fullname] - mov ecx, edi -.parseloop: - push esi -.parsename: - lodsb - test al, al - jz @f - cmp al, '/' - jnz .parsename -@@: -; we have found next component of current name; look for it in current directory - sub esi, [esp] - dec esi ; esi = strlen(component) - cmp esi, 259 - jbe @f - push ContinueBtn - push 1 - push aNameTooLong_ptr - push 1 - call [SayErr] - jmp return.clear -@@: - push ecx - mov eax, [ecx] ; eax->subfolders list - mov ecx, esi -.scansubfolders: - test eax, eax - jz .nofolder - add eax, [hOut] - cmp [eax+file_common.namelen], ecx - jnz .scancont - mov esi, [esp+4] - push ecx edi - mov edi, [eax+file_common.name] - repz cmpsb - pop edi ecx - jz .subfound -.scancont: - mov eax, [eax+file_common.next] - jmp .scansubfolders -.subfound: -; found subfolder, set it as current and continue parsing name - add [esp+4], ecx - pop ecx - lea ecx, [eax+file_common.subfolders] - pop esi - lodsb - test al, al - jnz .parseloop -; that was the last component of the name, and we have found subfolder -; so found subfolder is a virtual subfolder and must be replaced with current -; name - mov eax, [ecx-file_common.subfolders+file_common.namelen] - mov [edx+file_common.namelen], eax - sub esi, eax - dec esi - mov [edx+file_common.name], esi - sub edx, [hOut] ; convert pointer to relative -; replace item in L2-list - mov eax, [ecx-file_common.subfolders+file_common.prev] - test eax, eax - jnz .1 - mov eax, [ecx-file_common.subfolders+file_common.parent] - sub eax, file_common.next - file_common.subfolders - jnc .1 - lea eax, [edi-file_common.next] - jmp .2 -.1: - add eax, [hOut] -.2: - mov [eax+file_common.next], edx - mov eax, [ecx-file_common.subfolders+file_common.next] - test eax, eax - jnz .3 - mov eax, [ecx-file_common.subfolders+file_common.parent] - sub eax, file_common.prev - file_common.subfolders.end - jnc .3 - lea eax, [edi-file_common.prev+4] - jmp .4 -.3: - add eax, [hOut] -.4: - mov [eax+file_common.prev], edx -; correct parent links in childrens - mov eax, [ecx] -@@: - test eax, eax - jz @f - add eax, [hOut] - mov [eax+file_common.parent], edx - mov eax, [eax+file_common.next] - jmp @b -@@: - mov eax, [ecx+8] -@@: - test eax, eax - jz @f - add eax, [hOut] - mov [eax+file_common.parent], edx - mov eax, [eax+file_common.next] - jmp @b -@@: - add edx, [hOut] -; set children links - mov eax, [ecx] - mov [edx+file_common.subfolders], eax - mov eax, [ecx+4] - mov [edx+file_common.subfolders.end], eax - mov eax, [ecx+8] - mov [edx+file_common.subfiles], eax - mov eax, [ecx+12] - mov [edx+file_common.subfiles.end], eax - mov eax, [ecx+16] - mov [edx+file_common.NumSubItems], eax -; set prev/next links - mov eax, [ecx-file_common.subfolders+file_common.next] - mov [edx+file_common.next], eax - mov eax, [ecx-file_common.subfolders+file_common.prev] - mov [edx+file_common.prev], eax -; add old item to list of free items -uglobal -align 4 -init_file_links.free dd ? -endg - sub ecx, file_common.subfolders - mov eax, [.free] - mov [ecx], eax - sub ecx, [hOut] - mov [.free], ecx - jmp .mainloopcont -.nofolder: - mov eax, edx - mov esi, [esp+4] - cmp byte [esi+ecx], 0 - jz .newitem -; the current item is as 'dir1/item1' and 'dir1' has not been found -; allocate virtual subfolder 'dir1' - mov eax, [init_file_links.free] - test eax, eax - jz .realloc - add eax, [hOut] - push dword [eax] - pop [init_file_links.free] - jmp .allocated -.realloc: -; there is no free space, so reallocate [hOut] block - mov eax, [hOut] - sub [esp], eax ; make pointers relative - sub edx, eax - sub edi, eax - push ecx - mov ecx, [hOut.allocated] - add ecx, [esp+12+4] - mov [hOut.allocated], ecx - push ecx - and ecx, 0xFFF - cmp ecx, [esp+16+4] - pop ecx - ja @f - push edx - mov edx, eax - call [pgrealloc] - pop edx - test eax, eax - jnz @f - mov ecx, [hOut] - call [pgfree] - mov esp, [_esp] - or eax, -1 - ret -@@: - pop ecx - mov [hOut], eax - add [esp], eax ; make pointers absolute - add edx, eax - add edi, eax - add eax, [hOut.allocated] - sub eax, [esp+8+4] -.allocated: -; eax -> new item - mov [eax+file_common.bIsDirectory], 1 - mov [eax+file_common.bPseudoFolder], 1 -.newitem: - mov [eax+file_common.namelen], ecx -; !!! in this case .fullname is not null-terminated !!! - mov ecx, [edx+file_common.fullname] - mov [eax+file_common.fullname], ecx - push edi eax - lea edi, [eax+file_common.parent] - xor eax, eax - push 7 - pop ecx - rep stosd - pop eax edi - pop ecx - pop esi -; ecx = parent item, eax = current item - mov [eax+file_common.name], esi - inc dword [ecx+16] ; new item in parent folder - push ecx -; add new item to end of L2-list - cmp [eax+file_common.bIsDirectory], 0 - jnz @f - add ecx, 8 -@@: - push eax - sub eax, [hOut] - cmp dword [ecx], 0 - jnz @f - mov [ecx], eax -@@: - xchg eax, [ecx+4] - xchg eax, ecx - pop eax - mov [eax+file_common.prev], ecx - jecxz @f - add ecx, [hOut] - sub eax, [hOut] - mov [ecx+file_common.next], eax - add eax, [hOut] -@@: - pop ecx -; set parent link - cmp ecx, edi - jz @f - sub ecx, file_common.subfolders - sub ecx, [hOut] - mov [eax+file_common.parent], ecx -@@: -; set current directory to current item - lea ecx, [eax+file_common.subfolders] -; if that was not last component, continue parse name - add esi, [eax+file_common.namelen] - lodsb - test al, al - jnz .parseloop -.mainloopcont: -; continue main loop - add edx, [esp+4] - jmp .mainloop -.mainloopdone: -; Loop done. - ret 4 - -; This subroutine is called by getattr and open. -; This subroutine looks for file name and returns NULL or pointer to file info record. -lookup_file_name: - mov ebp, [esp+8] ; hPlugin - mov esi, [esp+12] ; filename - lea edi, [ebp+handle_common.root.subfolders] - xor eax, eax -; KFar operates with absolute names, skip first '/' - cmp byte [esi], '/' - jnz .notfound - inc esi -.mainloop: -; get next component of name - push -1 - pop ecx -@@: - inc ecx - cmp byte [esi+ecx], '/' - jz @f - cmp byte [esi+ecx], 0 - jnz @b -@@: -; esi->component, ecx=length -; scan for required item in subfolders list - push -1 - mov eax, [edi] ; .subfolders -.scan1: - test eax, eax - jz .notfound1 - add eax, ebp - cmp [eax+file_common.namelen], ecx - jnz .cont1 - push ecx esi edi - mov edi, [eax+file_common.name] - repz cmpsb - pop edi esi ecx - jz .found1 -.cont1: - mov eax, [eax+file_common.next] - jmp .scan1 -.notfound1: - pop edx -; if this is last component in file name, scan in subfiles list - cmp byte [esi+ecx], al - jnz .notfound - inc edx - jnz .notfound - mov eax, [edi+8] ; .subfiles - push edx - jmp .scan1 -.found1: - pop edi -; item is found, go to next component - lea edi, [eax+file_common.subfolders] - lea esi, [esi+ecx+1] - cmp byte [esi-1], 0 - jnz .mainloop -; this was the last component -.notfound: - ret - -; Memory streams handling. -; Archive handlers create memory stream for small files: -; size of which is not greater than (free RAM size)/4 and -; not greater than following constant... -;LIMIT_FOR_MEM_STREAM = 2*1024*1024 -; ...if it is defined. Now the definition is commented: -; if user has many physical memory, why not to use it? - -virtual at 0 -mem_stream: -.type dd ? ; type_mem_stream -.size dd ? -.pos dd ? -.buf: -end virtual - -; unsigned __stdcall read(ebx = HANDLE hFile, void* buf, unsigned size); -read_mem_stream: - mov eax, [esp+12] - mov ecx, [ebx+mem_stream.size] - sub ecx, [ebx+mem_stream.pos] - jnc @f - xor ecx, ecx -@@: - cmp eax, ecx - jb @f - mov eax, ecx -@@: - mov ecx, eax - lea esi, [ebx+mem_stream.buf] - add esi, [ebx+mem_stream.pos] - add [ebx+mem_stream.pos], eax - mov edi, [esp+8] - mov edx, ecx - shr ecx, 2 - rep movsd - mov ecx, edx - and ecx, 3 - rep movsb - ret 12 - -; void __stdcall setpos(ebx = HANDLE hFile, __int64 pos); -setpos_mem_stream: - mov eax, [esp+8] - mov [ebx+mem_stream.pos], eax - ret 12 - -; void __stdcall close(ebx = HANDLE hFile); -close_mem_stream: - mov ecx, ebx - call [pgfree] - ret 4 - -; Allocate handle for file -; esi -> handle table, ecx = size of handle -alloc_handle: -; Handle table is L2-list of allocated pages. -; Scan for free entry - mov edx, esi -@@: - mov edx, [edx] - cmp edx, esi - jz .alloc_new - mov eax, [edx+8] ; head of L1-list of free entries - test eax, eax ; has free entry? - jz @b -; we have found allocated page with free entry; allocate entry and return - inc dword [edx+12] ; number of busy entries - push dword [eax] - pop dword [edx+8] -.ret: - ret -.alloc_new: -; no free pages; get new page and initialize - push ecx - mov ecx, 0x1000 - call [pgalloc] - pop ecx - test eax, eax - jz .ret -; insert new page to start of L2-list - mov edx, [esi] - mov [eax], edx - mov [esi], eax - mov [eax+4], esi - mov [edx+4], eax - mov dword [eax+12], 1 ; 1 allocated entry -; initialize list of free entries - lea edx, [eax+16] - push edx ; save return value - add edx, ecx - mov [eax+8], edx - add eax, 0x1000 -@@: - mov esi, edx - add edx, ecx - mov [esi], edx - cmp edx, eax - jb @b - and dword [esi], 0 - pop eax - ret - -; Free handle allocated in previous procedure -; esi = handle -free_handle: - mov ecx, esi - and ecx, not 0xFFF ; get page -; add entry to head of L1-list of free entries - mov eax, [ecx+8] - mov [esi], eax - mov [ecx+8], esi - dec dword [ecx+12] ; decrement number of allocated entries - jnz .ret -; delete page from common L2-list - mov eax, [ecx] - mov edx, [ecx+4] - mov [eax+4], edx - mov [edx], eax -; free page - call [pgfree] -.ret: - ret - -; Ask user to enter password. -; Out: ZF set <=> user pressed Esc -; 'password_ansi', 'password_unicode', 'password_size' filled -query_password: - cmp [bPasswordDefined], 0 - jnz .ret - mov edi, password_data - mov eax, password_maxlen - stosd ; maximum length - xor eax, eax - stosd ; start of visible part - stosd ; position of cursor - stosb ; initial state: empty string - mov eax, [cur_console_size] - mov eax, [eax] ; get current console width - sub eax, 12 - mov edi, password_dlg - mov [edi+password_dlg.width-password_dlg], eax - dec eax - dec eax - mov [edi+password_dlg.width1-password_dlg], eax - mov [edi+password_dlg.width2-password_dlg], eax - push edi - call [DialogBox] - inc eax - jz .ret -; convert ANSI-cp866 to UNICODE string; also calculate 'password_size' - mov esi, password_ansi - mov edi, password_unicode - or [password_size], -1 -.cvt: - inc [password_size] - lodsb - mov ah, 0 -; 0x00-0x7F - trivial map - cmp al, 0x80 - jb .symb -; 0x80-0xAF -> 0x410-0x43F - cmp al, 0xB0 - jae @f - add ax, 0x410-0x80 - jmp .symb -@@: -; 0xE0-0xEF -> 0x440-0x44F - cmp al, 0xE0 - jb .unk - cmp al, 0xF0 - jae @f - add ax, 0x440-0xE0 - jmp .symb -@@: -; 0xF0 -> 0x401 -; 0xF1 -> 0x451 - cmp al, 'Ё' - jz .yo1 - cmp al, 'ё' - jz .yo2 -.unk: - mov al, '_' - jmp .symb -.yo1: - mov ax, 0x401 - jmp .symb -.yo2: - mov ax, 0x451 -.symb: - stosw - test al, al - jnz .cvt - inc [bPasswordDefined] ; clears ZF flag -.ret: - ret - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;; API for other programs ;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; void* __stdcall deflate_unpack(void* packed_data, unsigned* pLength) -deflate_unpack: - push dword [esp+8] - push esp - push deflate_unpack_cb - call deflate_unpack2 - ret 8 - -deflate_unpack_cb: - mov edx, [esp+4] - push edx - mov edx, [edx+12] - mov edx, [edx] - mov eax, [esp+8+4] - mov [eax], edx - pop edx - xor eax, eax - xchg eax, [edx+8] - ret 8 - -; void* __stdcall deflate_unpack2(void* get_next_chunk, void* parameter, unsigned* pUnpackedLength) -; void* __stdcall get_next_chunk(void* parameter, unsigned* pLength) -deflate_unpack2: - pusha - mov ecx, 0x11000 - call mypgalloc - test eax, eax - jz .ret - or dword [eax+streamInfo.fullSize], -1 - or dword [eax+streamInfo.fullSize+4], -1 - and dword [eax+streamInfo.bufSize], 0 - mov dword [eax+streamInfo.fillBuf], .fillBuf - mov edx, [esp+32+4] - mov [eax+streamInfo.size], edx - mov edx, [esp+32+8] - mov [eax+streamInfo.size+4], edx - mov [eax+streamInfo.size+8+deflate_decoder.inStream], eax - add eax, streamInfo.size+8 - lea edi, [eax+deflate_decoder.size] - mov [eax+streamInfo.bufPtr], edi - mov ebp, eax - call deflate_init_decoder - xor edx, edx - mov ecx, 10000h -.loop: - push @f - pushad - mov [_esp], esp - mov [_ebp], ebp - mov [error_proc], .error - mov ecx, 10000h - jmp [eax+streamInfo.fillBuf] -@@: - push SF_SYS_MISC - pop eax - push SSF_MEM_REALLOC - pop ebx - int 0x40 - test eax, eax - jz .nomem - mov edx, eax - mov eax, ebp - mov esi, edi - push edi - lea edi, [edx+ecx-0x10000] - push ecx - mov ecx, 0x10000/4 - rep movsd - pop ecx - pop edi - add ecx, 0x10000 - jmp .loop -.error: - pop eax - push edi - popad - pop eax - mov eax, ebp - lea esi, [eax+deflate_decoder.size] - sub ecx, 0x10000 - sub edi, esi - add ecx, edi - mov eax, [esp+32+12] - test eax, eax - jz @f - mov [eax], ecx -@@: - test ecx, ecx - jnz @f - inc ecx -@@: - push SF_SYS_MISC - pop eax - push SSF_MEM_REALLOC - pop ebx - int 0x40 - test eax, eax - jz .nomem - sub ecx, edi - mov edx, edi - lea edi, [eax+ecx] - mov ecx, edx - shr ecx, 2 - rep movsd - mov ecx, edx - and ecx, 3 - rep movsb - push eax - push SF_SYS_MISC - pop eax - push SSF_MEM_FREE - pop ebx - lea ecx, [ebp-streamInfo.size-8] - int 40h - pop eax - jmp .ret -.nomem: - push SF_SYS_MISC - pop eax - push SSF_MEM_FREE - pop ebx - test edx, edx - jz @f - mov ecx, edx - push eax - int 0x40 - pop eax -@@: - lea ecx, [ebp-streamInfo.size-8] - int 0x40 - xor eax, eax -.ret: - mov [esp+28], eax - popa - ret 12 -.fillBuf: - push eax - push eax - push esp - push dword [eax+streamInfo.size+4] - call dword [eax+streamInfo.size] - pop edx - pop ebp - mov [ebp+streamInfo.bufPtr], eax - and [ebp+streamInfo.bufDataLen], 0 - test eax, eax - jz @f - mov [ebp+streamInfo.bufDataLen], edx -@@: - popad - ret - -mypgalloc: - push SF_SYS_MISC - pop eax - push SSF_MEM_ALLOC - pop ebx - int 0x40 - ret - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;; Initialized data ;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -; export table -align 4 -EXPORTS: - dd aVersion, 3 - dd aPluginLoad, plugin_load - dd aOpenFilePlugin,OpenFilePlugin - dd aClosePlugin, ClosePlugin - dd aReadFolder, ReadFolder - dd aSetFolder, SetFolder - dd aGetFiles, GetFiles - dd aGetOpenPluginInfo, GetOpenPluginInfo - dd aGetattr, mygetattr - dd aOpen, myopen - dd aRead, myread - dd aSetpos, mysetpos - dd aClose, myclose - dd aDeflateUnpack, deflate_unpack - dd aDeflateUnpack2,deflate_unpack2 - dd adeflateInit, deflateInit - dd adeflateInit2, deflateInit2 - dd adeflateReset, deflateReset - dd adeflate, deflate - dd adeflateEnd, deflateEnd - dd azError, zError - dd acalc_crc32, calc_crc32 - dd 0 - -; exported names -aVersion db 'version',0 -aPluginLoad db 'plugin_load',0 -aOpenFilePlugin db 'OpenFilePlugin',0 -aClosePlugin db 'ClosePlugin',0 -aReadFolder db 'ReadFolder',0 -aSetFolder db 'SetFolder',0 -aGetFiles db 'GetFiles',0 -aGetOpenPluginInfo db 'GetOpenPluginInfo',0 -aGetattr db 'getattr',0 -aOpen db 'open',0 -aRead db 'read',0 -aSetpos db 'setpos',0 -aClose db 'close',0 -aDeflateUnpack db 'deflate_unpack',0 -aDeflateUnpack2 db 'deflate_unpack2',0 -adeflateInit db 'deflateInit',0 -adeflateInit2 db 'deflateInit2',0 -adeflateReset db 'deflateReset',0 -adeflate db 'deflate',0 -adeflateEnd db 'deflateEnd',0 -azError db 'zError',0 -acalc_crc32 db 'calc_crc32',0 - -; common strings -if lang eq ru_RU -aContinue db 'Продолжить',0 -aCancel db 'Отмена',0 -aHeaderError db 'Ошибка в заголовке архива',0 -aReadError db 'Ошибка чтения',0 -aNoFreeRam db 'Недостаточно свободной оперативной памяти',0 -aEncodingProblem db 'Проблема с кодировкой',0 -aEncodingProblem_str db 'Имена некоторых файлов в архиве содержат символы,',0 -.2 db 'не представимые в кодировке cp866.',0 -.3 db 'Эти символы будут заменены на подчёркивания.',0 -aEnterPassword db 'Введите пароль:',0 -aEnterPasswordLen = $ - aEnterPassword - 1 -aEnterPasswordTitle db 'Ввод пароля',0 -aArchiveDataError db 'Ошибка в данных архива',0 -aArchiveDataErrorPass db 'Ошибка в данных архива или неверный пароль',0 -aChangePass db 'Ввести пароль',0 -aNameTooLong db 'Слишком длинное имя',0 -aCannotOpenFile db 'Не могу открыть файл',0 -else -aContinue db 'Continue',0 -aCancel db 'Cancel',0 -aHeaderError db 'Invalid archive header',0 -aReadError db 'Read error',0 -aNoFreeRam db 'There is not enough of free RAM',0 -aEncodingProblem db 'Encoding problem',0 -aEncodingProblem_str db 'The names of some files in the archive contain',0 -.2 db 'characters which can not be represented in cp866.',0 -.3 db 'Such characters will be replaced to underscores.',0 -aEnterPassword db 'Enter password:',0 -aEnterPasswordLen = $ - aEnterPassword - 1 -aEnterPasswordTitle db 'Get password',0 -aArchiveDataError db 'Error in archive data',0 -aArchiveDataErrorPass db 'Error in archive data or incorrect password',0 -aChangePass db 'Enter password',0 -aNameTooLong db 'Name is too long',0 -aCannotOpenFile db 'Cannot open file',0 -end if - -; kfar_arc supports many archive types. -; OpenFilePlugin looks for supported archive signature and gives control -; to concrete handler if found. -; Other functions just determine type of opened archive and jump to corresponding handler. -type_mem_stream = 0 ; memory stream - for file handles (returned from 'open') -type_7z = 1 -type_zip = 2 - -; archive functions (types start from type_7z) -align 4 -ClosePluginTable: - dd close_7z - dd close_zip -getattrTable: - dd getattr_7z - dd getattr_zip -openTable: - dd open_file_7z - dd open_file_zip -basesizes: - dd handle_7z.basesize, file_in_7z.size - dd handle_zip.basesize, file_in_zip.size - -; file functions (types start from type_mem_stream) -readTable: - dd read_mem_stream - dd read_7z - dd read_zip -setposTable: - dd setpos_mem_stream - dd setpos_7z - dd setpos_zip -closeTable: - dd close_mem_stream - dd close_file_7z - dd close_file_zip - -; pointers for SayErr and Message -ContinueBtn dd aContinue -HeaderError_ptr dd aHeaderError -aReadError_ptr dd aReadError -aNoFreeRam_ptr dd aNoFreeRam -aEncodingProblem_str_ptr: - dd aEncodingProblem_str - dd aEncodingProblem_str.2 - dd aEncodingProblem_str.3 -aNameTooLong_ptr dd aNameTooLong -aArchiveDataError_ptr dd aArchiveDataError -aArchiveDataErrorPass_ptr dd aArchiveDataErrorPass -CancelPassBtn dd aCancel - dd aChangePass - -; "enter password" dialog for KFar -password_dlg: - dd 1 ; use standard dialog colors - dd -1 ; center window by x - dd -1 ; center window by y -.width dd ? ; width (will be filled according to current console width) - dd 2 ; height - dd 4, 2 ; border size - dd aEnterPasswordTitle ; title - dd ? ; colors (will be set by KFar) - dd 0 ; used internally by dialog manager, ignored - dd 0, 0 ; reserved for DlgProc - dd 2 ; 2 controls -; the string "enter password" - dd 1 ; type: static - dd 1,0 ; upper-left position -.width1 dd ?,0 ; bottom-right position - dd aEnterPassword ; data - dd 0 ; flags -; editbox for password - dd 3 ; type: edit - dd 1,1 ; upper-left position -.width2 dd ?,0 ; bottom-right position - dd password_data ; data - dd 2Ch ; flags - -IncludeIGlobals - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;; Uninitialized data ;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -purge data ;used in 'macros.inc' -purge section ;used in 'macros.inc' - -section '.udata' data readable writable align 16 -kfar_info dd ? -crc_table rd 256 -_esp dd ? -_ebp dd ? -bufsize dd ? -bufptr dd ? -bufend dd ? -buffer rb 1024 -inStream dd ? -hOut dd ? -.allocated dd ? - -error_proc dd ? -clear_proc dd ? - -; import from kfar -open2 dd ? -filesize dd ? -read dd ? -seek dd ? -close dd ? -pgalloc dd ? -pgrealloc dd ? -pgfree dd ? -getfreemem dd ? -DialogBox dd ? -SayErr dd ? -Message dd ? -cur_console_size dd ? - -; data for editbox in kfar dialog -password_maxlen = 512 -password_data: -.maxlen dd ? -.pos dd ? -.start dd ? -password_ansi rb password_maxlen+1 -bPasswordDefined db ? - -; converted password -password_unicode rw password_maxlen+1 -password_size dd ? - -IncludeUGlobals - -bWasWarning db ? +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + +; +; project name: KFar_Arc - plugin for KFar, which supports various archives +; target platform: KolibriOS +; compiler: FASM 1.67.14 +; version: 0.17 +; last update: 2016-11-04 (Nov 04, 2016) +; minimal KFar version: 0.43 +; minimal kernel: no limit +; +; author: Diamond +; email: diamondz@land.ru +; web: http://diamond.kolibrios.org +; + +; standard start of Kolibri dynamic library +format MS COFF +public EXPORTS + +section '.flat' code readable align 16 + +; include auxiliary procedures +include 'kglobals.inc' ; iglobal/uglobal +include 'lang.inc' ; define language for localized strings +include 'crc.inc' ; CRC32 calculation +include 'sha256.inc' ; SHA-256 hash algorithm +include 'aes.inc' ; AES crypto algorithm +; include main code for archives loading +include '7z.inc' ; *.7z +include 'lzma.inc' ; LZMA-decoder for *.7z +include 'ppmd.inc' ; PPMD-decoder for *.7z +include '7zbranch.inc' ; branch filters for *.7z +include '7zaes.inc' ; AES cryptor for *.7z +include 'zip.inc' ; *.zip +include 'deflate.inc' ; Deflate[64] decoder for *.7z and *.zip +include '../zlib/zlib.asm' ; deflate coder + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;; Interface for KFar ;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +virtual at 0 +kfar_info_struc: +.lStructSize dd ? +.kfar_ver dd ? +.open dd ? +.open2 dd ? +.read dd ? +.write dd ? +.seek dd ? +.tell dd ? +.flush dd ? +.filesize dd ? +.close dd ? +.pgalloc dd ? +.pgrealloc dd ? +.pgfree dd ? +.getfreemem dd ? +.pgalloc2 dd ? +.pgrealloc2 dd ? +.pgfree2 dd ? +.menu dd ? +.menu_centered_in dd ? +.DialogBox dd ? +.SayErr dd ? +.Message dd ? +.cur_console_size dd ? +end virtual + +; int __stdcall plugin_load(kfar_info* info); +; Initialization of plugin + Save used KFar functions. +plugin_load: + mov eax, [esp+4] + mov [kfar_info], eax + push [eax+kfar_info_struc.open2] + pop [open2] + push [eax+kfar_info_struc.filesize] + pop [filesize] + push [eax+kfar_info_struc.read] + pop [read] + push [eax+kfar_info_struc.seek] + pop [seek] + push [eax+kfar_info_struc.close] + pop [close] + lea esi, [eax+kfar_info_struc.DialogBox] + mov edi, DialogBox + movsd + movsd + movsd + movsd + lea esi, [eax+kfar_info_struc.pgalloc] + mov edi, pgalloc + movsd + movsd + movsd + movsd + call init_crc_table + call init_aes + call init_ppmd + xor eax, eax ; success + ret 4 + +; HANDLE __stdcall OpenFilePlugin(HANDLE basefile, +; const void* attr, const void* data, int datasize, +; int baseplugin_id, HANDLE baseplugin_instance, const char* name); +; This function is called when user presses Enter (or Ctrl+PgDn) on file. +; Plugin tests whether given file is of supported type +; and if so, loads information and returns +; handle to be used in subsequent calls to ReadFolder, SetFolder and so on. +OpenFilePlugin: + mov [bPasswordDefined], 0 + mov esi, [esp+12] + mov ebp, [esp+4] +; test for 7z archive + cmp dword [esp+16], 20h ; minimal size of 7z archive is 20h bytes + jb .no_7z + cmp word [esi], '7z' ; signature, part 1 + jnz .no_7z + cmp dword [esi+2], 0x1C27AFBC ; signature, part 2 + jnz .no_7z + call open_7z + ret 28 +.no_7z: +; test for zip archive + cmp dword [esp+16], 22 ; minimal size of zip archive is 22 bytes + jb .no_zip + cmp word [esi], 0x4B50 + jnz .no_zip + cmp word [esi+2], 0x0403 + jz .zip + cmp word [esi+2], 0x0201 + jz .zip + cmp word [esi+2], 0x0606 + jz .zip + cmp word [esi+2], 0x0706 + jz .zip + cmp word [esi+2], 0x0605 + jnz .no_zip +.zip: + call open_zip + ret 28 +.no_zip: + xor eax, eax + ret 28 + +; Handle of plugin in kfar_arc is as follow: +virtual at 0 +handle_common: +.type dd ? +.root.subfolders dd ? +.root.subfolders.end dd ? +.root.subfiles dd ? +.root.subfiles.end dd ? +.root.NumSubItems dd ? +.curdir dd ? +.NumFiles dd ? +; ... some plugin-specific data follows ... +end virtual + +; and for each archive item there is one file info structure, which begins as follow: +virtual at 0 +file_common: +.fullname dd ? ; pointer to cp866 string +.name dd ? ; name without path (end of .fullname) +.namelen dd ? ; strlen(.name) +.bIsDirectory db ? +.bPseudoFolder db ? + rb 2 +.parent dd ? ; pointer to parent directory record +.subfolders dd ? ; head of L2-list of subfolders [for folders] +.subfolders.end dd ? +.subfiles dd ? ; head of L2-list of files [for folders] +.subfiles.end dd ? +.NumSubItems dd ? +.next dd ? ; next item in list of subfolders/files +.prev dd ? ; previous item in list of subfolders/files +.stamp dd ? ; stamp for GetFiles +end virtual + +; void __stdcall ClosePlugin(HANDLE hPlugin); +; This function frees all resources allocated in OpenFilePlugin. +ClosePlugin: + mov eax, [esp+4] ; get hPlugin + mov eax, [eax] ; hPlugin is pointer to internal data structure + ; first dword is archive type (type_xxx constants) + dec eax ; types start from 1 + jmp dword [ClosePluginTable+eax*4] + +; int __stdcall ReadFolder(HANDLE hPlugin, +; unsigned dirinfo_start, unsigned dirinfo_size, void* dirdata); +ReadFolder: +; init header + mov edi, [esp+16] + mov ecx, 32/4 + xor eax, eax + rep stosd + mov byte [edi-32], 1 ; version + mov ebp, [esp+4] +; get current directory + lea ebx, [ebp+handle_common.root.subfolders] + cmp [ebp+handle_common.curdir], 0 + jz @f + mov ebx, [ebp+handle_common.curdir] + add ebx, file_common.subfolders +@@: + mov ecx, [ebx+16] + mov [edi-24], ecx ; number of files +; edi points to BDFE + push 6 ; assume EOF + pop eax + sub ecx, [esp+8] + ja @f + and dword [edi-28], 0 ; number of files read + ret 10h +@@: + cmp ecx, [esp+12] + jb @f + mov ecx, [esp+12] + xor eax, eax ; OK +@@: + mov [edi-28], ecx + push eax +; copy files data + jecxz .done +; seek to required item + mov eax, [esp+8+4] + mov esi, [ebx] +.0: + test esi, esi + jnz .1 + mov esi, [ebx+8] +.1: + add esi, ebp + dec eax + js .2 + mov esi, [esi+file_common.next] + jmp .0 +.2: +.copy: + pushad + mov eax, esi + mov ecx, [ebp] + call dword [getattrTable+(ecx-1)*4] + pop edi esi + push esi edi + add edi, 40 + mov ecx, [esi+file_common.namelen] + mov esi, [esi+file_common.name] + rep movsb + mov byte [edi], 0 + popad + add edi, 304 + mov esi, [esi+file_common.next] + test esi, esi + jnz @f + mov esi, [ebx+8] +@@: + add esi, ebp + loop .copy +.done: + pop eax + ret 10h + +; bool __stdcall SetFolder(HANDLE hPlugin, +; const char* relative_path, const char* absolute_path); +SetFolder: + mov ebp, [esp+4] + mov edx, [ebp+handle_common.curdir] + mov esi, [esp+8] + cmp dword [esi], '..' + jz .toparent + xor ecx, ecx +@@: + inc ecx + cmp byte [esi+ecx], 0 + jnz @b + mov ebx, [ebp+handle_common.root.subfolders] + test edx, edx + jz .scan + mov ebx, [edx+file_common.subfolders] +.scan: + test ebx, ebx + jz .err + add ebx, ebp + cmp [ebx+file_common.namelen], ecx + jnz .cont + push ecx esi + mov edi, [ebx+file_common.name] + repz cmpsb + pop esi ecx + jz .set +.cont: + mov ebx, [ebx+file_common.next] + jmp .scan +.toparent: + test edx, edx + jz .err + mov ebx, [edx+file_common.parent] + test ebx, ebx + jz @f + add ebx, ebp +@@: +.set: + mov [ebp+handle_common.curdir], ebx + mov al, 1 + ret 12 +.err: + xor eax, eax + ret 12 + +iglobal +cur_stamp dd 0 +endg + +uglobal +tmp_bdfe rb 304 +endg + +; void __stdcall GetFiles(HANDLE hPlugin, int NumItems, void* items[], +; void* addfile, void* adddir); +; bool __stdcall addfile(const char* name, void* bdfe_info, HANDLE hFile); +; bool __stdcall adddir(const char* name, void* bdfe_info); +GetFiles: + mov ebp, [esp+4] + mov ecx, [ebp+handle_common.NumFiles] + test ecx, ecx + jz .ret + mov ebx, ebp + mov eax, [ebx] + add ebx, [basesizes+(eax-1)*8] + inc [cur_stamp] +.loop: + push ecx + mov esi, [ebx+file_common.fullname] + mov edx, [ebp+handle_common.curdir] + test edx, edx + jz .incur + mov eax, [cur_stamp] + mov [edx+file_common.stamp], eax + mov edi, [edx+file_common.fullname] + mov ecx, [edx+file_common.namelen] + add ecx, [edx+file_common.name] + sub ecx, edi + repz cmpsb + jnz .cont +.incur: + cmp byte [esi], '/' + jnz @f + inc esi +@@: + mov ecx, [esp+12] ; NumItems + mov edx, [esp+16] ; items + cmp ecx, -1 + jz .ok +.check: + sub ecx, 1 + js .cont + push esi + mov edi, [edx] + add edi, 40 +@@: + lodsb + scasb + jnz @f + test al, al + jz .ok2 + jmp @b +@@: + pop esi + cmp al, '/' + jnz @f + cmp byte [edi-1], 0 + jz .ok +@@: + add edx, 4 + jmp .check +.ok2: + pop esi +.ok: +; add all parents directories if needed +.parloope: + mov ecx, [ebx+file_common.parent] + jecxz .pardone + add ecx, ebp + mov eax, [cur_stamp] + cmp [ecx+file_common.stamp], eax + jz .pardone +.parloopi: + mov edx, ecx + mov ecx, [ecx+file_common.parent] + jecxz @f + add ecx, ebp + cmp [ecx+file_common.stamp], eax + jnz .parloopi +@@: + mov [edx+file_common.stamp], eax + push esi + mov ecx, [edx+file_common.name] + add ecx, [edx+file_common.namelen] + xor eax, eax + xchg al, [ecx] + push eax ecx + mov eax, edx + mov edi, tmp_bdfe + push edi + sub esi, [ebx+file_common.fullname] + add esi, [edx+file_common.fullname] + push esi + mov ecx, [ebp] + call dword [getattrTable+(ecx-1)*4] + mov eax, [esp+24+20] + call eax + pop ecx edx + mov [ecx], dl + pop esi + test al, al + jz .forced_exit + jmp .parloope +.pardone: + cmp [ebx+file_common.bIsDirectory], 0 + jz .addfile + mov eax, [cur_stamp] + cmp [ebx+file_common.stamp], eax + jz .cont + mov [ebx+file_common.stamp], eax + push esi + mov ecx, [ebx+file_common.name] + add ecx, [ebx+file_common.namelen] + xor eax, eax + xchg al, [ecx] + push eax ecx + mov eax, ebx + mov edi, tmp_bdfe + push edi + push esi + mov ecx, [ebp] + call dword [getattrTable+(ecx-1)*4] + mov eax, [esp+24+20] + call eax + pop ecx edx + mov [ecx], dl + pop esi + test al, al + jz .forced_exit + jmp .cont +.addfile: + push ebx esi ebp + push 11h + pop edi + mov eax, ebx + mov ecx, [ebp] + call dword [openTable+(ecx-1)*4] + pop ebp esi ebx + test eax, eax + jz .cont + push eax + push eax + mov edi, tmp_bdfe + push edi + push esi + mov eax, ebx + mov ecx, [ebp] + call dword [getattrTable+(ecx-1)*4] + mov eax, [esp+20+16] + call eax + pop ecx + push eax ebp + push ebx + push ecx + call myclose + pop ebx + pop ebp eax + test al, al + jz .forced_exit +.cont: + mov eax, [ebp] + add ebx, [basesizes+(eax-1)*8+4] + pop ecx + dec ecx + jnz .loop +.ret: + ret 20 +.forced_exit: + pop ecx + jmp .ret + +; void __stdcall GetOpenPluginInfo(HANDLE hPlugin, OpenPluginInfo* info); +GetOpenPluginInfo: + mov eax, [esp+8] ; get info ptr + mov byte [eax], 3 ; flags: add non-existing '..' entry automatically + ; use GetFiles for copying + ret 8 + +; int __stdcall getattr(HANDLE hPlugin, const char* filename, void* info); +mygetattr: + call lookup_file_name + test eax, eax + jz @f + mov edx, [ebp] + dec edx + mov edi, [esp+12] ; info ptr + call dword [getattrTable+edx*4] + xor eax, eax + ret 12 +@@: + mov al, 5 ; ERROR_FILE_NOT_FOUND + ret 12 + +; HANDLE __stdcall open(HANDLE hPlugin, const char* filename, int mode); +myopen: + call lookup_file_name + test eax, eax + jz @f + mov edx, [ebp] + dec edx + mov edi, [esp+12] ; mode + call dword [openTable+edx*4] +@@: + ret 12 + +; unsigned __stdcall read(HANDLE hFile, void* buf, unsigned size); +myread: + mov ebx, [esp+4] + mov eax, [ebx] + jmp dword [readTable+eax*4] + +; void __stdcall setpos(HANDLE hFile, __int64 pos); +mysetpos: + mov ebx, [esp+4] + mov eax, [ebx] + jmp dword [setposTable+eax*4] + +; void __stdcall close(HANDLE hFile); +myclose: + mov ebx, [esp+4] + mov eax, [ebx] + jmp dword [closeTable+eax*4] + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;; Auxiliary procedures ;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; return.err and return.clear are labels to jmp if something is invalid +; the caller must previously define [_esp], [_ebp] and [error_proc], [clear_proc] +return.err: + mov esp, [_esp] + mov ebp, [_ebp] + jmp [error_proc] +return.clear: + mov esp, [_esp] + mov ebp, [_ebp] + jmp [clear_proc] + +; data for following routine +iglobal +align 4 +_24 dd 24 +_60 dd 60 +_10000000 dd 10000000 +days400year dd 365*400+100-4+1 +days100year dd 365*100+25-1 +days4year dd 365*4+1 +days1year dd 365 +months dd 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +months2 dd 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +_400 dd 400 +_100 dd 100 +endg + +; Convert QWORD FILETIME to BDFE format. +ntfs_datetime_to_bdfe: +; edx:eax = number of 100-nanosecond intervals since January 1, 1601, in UTC + push eax + mov eax, edx + xor edx, edx + div [_10000000] + xchg eax, [esp] + div [_10000000] + pop edx +; edx:eax = number of seconds since January 1, 1601 + push eax + mov eax, edx + xor edx, edx + div [_60] + xchg eax, [esp] + div [_60] + mov [edi], dl + pop edx +; edx:eax = number of minutes + div [_60] + mov [edi+1], dl +; eax = number of hours (note that 2^64/(10^7*60*60) < 2^32) + xor edx, edx + div [_24] + mov [edi+2], dl + mov [edi+3], byte 0 +; eax = number of days since January 1, 1601 + xor edx, edx + div [days400year] + imul eax, 400 + add eax, 1601 + mov [edi+6], ax + mov eax, edx + xor edx, edx + div [days100year] + cmp al, 4 + jnz @f + dec eax + add edx, [days100year] +@@: + imul eax, 100 + add [edi+6], ax + mov eax, edx + xor edx, edx + div [days4year] + shl eax, 2 + add [edi+6], ax + mov eax, edx + xor edx, edx + div [days1year] + cmp al, 4 + jnz @f + dec eax + add edx, [days1year] +@@: + add [edi+6], ax + push esi edx + mov esi, months + movzx eax, word [edi+6] + test al, 3 + jnz .noleap + xor edx, edx + push eax + div [_400] + pop eax + test edx, edx + jz .leap + xor edx, edx + div [_100] + test edx, edx + jz .noleap +.leap: + mov esi, months2 +.noleap: + pop edx + xor eax, eax + inc eax +@@: + sub edx, [esi] + jb @f + add esi, 4 + inc eax + jmp @b +@@: + add edx, [esi] + pop esi + inc edx + mov [edi+4], dl + mov [edi+5], al + add edi, 8 + ret + +; By given array of files information, initialize links between them +; ("[folder] contains [item]" relations). +; Information structure must be compatible with 'file_common'. +; Size of information structure is in [esp+4]. +init_file_links: +; in: edx->file infos, ebx = number of files, [esp+4] = size, +; edi->{dd root.subfolders, dd root.subfolders.end, +; dd root.subfiles, dd root.subfiles.end, dd root.NumItems} + xor eax, eax + mov [.free], eax + push edi + stosd + stosd + stosd + stosd + stosd + pop edi +; Loop through all files +.mainloop: + dec ebx + js .mainloopdone +; Parse file name +; esi->current character in name +; dword [esp] = start of current component in file name +; ecx->{dd curdir.subfolders, dd curdir.subfolders.end, +; dd curdir.subfiles, dd curdir.subfiles.end} + mov esi, [edx+file_common.fullname] + mov ecx, edi +.parseloop: + push esi +.parsename: + lodsb + test al, al + jz @f + cmp al, '/' + jnz .parsename +@@: +; we have found next component of current name; look for it in current directory + sub esi, [esp] + dec esi ; esi = strlen(component) + cmp esi, 259 + jbe @f + push ContinueBtn + push 1 + push aNameTooLong_ptr + push 1 + call [SayErr] + jmp return.clear +@@: + push ecx + mov eax, [ecx] ; eax->subfolders list + mov ecx, esi +.scansubfolders: + test eax, eax + jz .nofolder + add eax, [hOut] + cmp [eax+file_common.namelen], ecx + jnz .scancont + mov esi, [esp+4] + push ecx edi + mov edi, [eax+file_common.name] + repz cmpsb + pop edi ecx + jz .subfound +.scancont: + mov eax, [eax+file_common.next] + jmp .scansubfolders +.subfound: +; found subfolder, set it as current and continue parsing name + add [esp+4], ecx + pop ecx + lea ecx, [eax+file_common.subfolders] + pop esi + lodsb + test al, al + jnz .parseloop +; that was the last component of the name, and we have found subfolder +; so found subfolder is a virtual subfolder and must be replaced with current +; name + mov eax, [ecx-file_common.subfolders+file_common.namelen] + mov [edx+file_common.namelen], eax + sub esi, eax + dec esi + mov [edx+file_common.name], esi + sub edx, [hOut] ; convert pointer to relative +; replace item in L2-list + mov eax, [ecx-file_common.subfolders+file_common.prev] + test eax, eax + jnz .1 + mov eax, [ecx-file_common.subfolders+file_common.parent] + sub eax, file_common.next - file_common.subfolders + jnc .1 + lea eax, [edi-file_common.next] + jmp .2 +.1: + add eax, [hOut] +.2: + mov [eax+file_common.next], edx + mov eax, [ecx-file_common.subfolders+file_common.next] + test eax, eax + jnz .3 + mov eax, [ecx-file_common.subfolders+file_common.parent] + sub eax, file_common.prev - file_common.subfolders.end + jnc .3 + lea eax, [edi-file_common.prev+4] + jmp .4 +.3: + add eax, [hOut] +.4: + mov [eax+file_common.prev], edx +; correct parent links in childrens + mov eax, [ecx] +@@: + test eax, eax + jz @f + add eax, [hOut] + mov [eax+file_common.parent], edx + mov eax, [eax+file_common.next] + jmp @b +@@: + mov eax, [ecx+8] +@@: + test eax, eax + jz @f + add eax, [hOut] + mov [eax+file_common.parent], edx + mov eax, [eax+file_common.next] + jmp @b +@@: + add edx, [hOut] +; set children links + mov eax, [ecx] + mov [edx+file_common.subfolders], eax + mov eax, [ecx+4] + mov [edx+file_common.subfolders.end], eax + mov eax, [ecx+8] + mov [edx+file_common.subfiles], eax + mov eax, [ecx+12] + mov [edx+file_common.subfiles.end], eax + mov eax, [ecx+16] + mov [edx+file_common.NumSubItems], eax +; set prev/next links + mov eax, [ecx-file_common.subfolders+file_common.next] + mov [edx+file_common.next], eax + mov eax, [ecx-file_common.subfolders+file_common.prev] + mov [edx+file_common.prev], eax +; add old item to list of free items +uglobal +align 4 +init_file_links.free dd ? +endg + sub ecx, file_common.subfolders + mov eax, [.free] + mov [ecx], eax + sub ecx, [hOut] + mov [.free], ecx + jmp .mainloopcont +.nofolder: + mov eax, edx + mov esi, [esp+4] + cmp byte [esi+ecx], 0 + jz .newitem +; the current item is as 'dir1/item1' and 'dir1' has not been found +; allocate virtual subfolder 'dir1' + mov eax, [init_file_links.free] + test eax, eax + jz .realloc + add eax, [hOut] + push dword [eax] + pop [init_file_links.free] + jmp .allocated +.realloc: +; there is no free space, so reallocate [hOut] block + mov eax, [hOut] + sub [esp], eax ; make pointers relative + sub edx, eax + sub edi, eax + push ecx + mov ecx, [hOut.allocated] + add ecx, [esp+12+4] + mov [hOut.allocated], ecx + push ecx + and ecx, 0xFFF + cmp ecx, [esp+16+4] + pop ecx + ja @f + push edx + mov edx, eax + call [pgrealloc] + pop edx + test eax, eax + jnz @f + mov ecx, [hOut] + call [pgfree] + mov esp, [_esp] + or eax, -1 + ret +@@: + pop ecx + mov [hOut], eax + add [esp], eax ; make pointers absolute + add edx, eax + add edi, eax + add eax, [hOut.allocated] + sub eax, [esp+8+4] +.allocated: +; eax -> new item + mov [eax+file_common.bIsDirectory], 1 + mov [eax+file_common.bPseudoFolder], 1 +.newitem: + mov [eax+file_common.namelen], ecx +; !!! in this case .fullname is not null-terminated !!! + mov ecx, [edx+file_common.fullname] + mov [eax+file_common.fullname], ecx + push edi eax + lea edi, [eax+file_common.parent] + xor eax, eax + push 7 + pop ecx + rep stosd + pop eax edi + pop ecx + pop esi +; ecx = parent item, eax = current item + mov [eax+file_common.name], esi + inc dword [ecx+16] ; new item in parent folder + push ecx +; add new item to end of L2-list + cmp [eax+file_common.bIsDirectory], 0 + jnz @f + add ecx, 8 +@@: + push eax + sub eax, [hOut] + cmp dword [ecx], 0 + jnz @f + mov [ecx], eax +@@: + xchg eax, [ecx+4] + xchg eax, ecx + pop eax + mov [eax+file_common.prev], ecx + jecxz @f + add ecx, [hOut] + sub eax, [hOut] + mov [ecx+file_common.next], eax + add eax, [hOut] +@@: + pop ecx +; set parent link + cmp ecx, edi + jz @f + sub ecx, file_common.subfolders + sub ecx, [hOut] + mov [eax+file_common.parent], ecx +@@: +; set current directory to current item + lea ecx, [eax+file_common.subfolders] +; if that was not last component, continue parse name + add esi, [eax+file_common.namelen] + lodsb + test al, al + jnz .parseloop +.mainloopcont: +; continue main loop + add edx, [esp+4] + jmp .mainloop +.mainloopdone: +; Loop done. + ret 4 + +; This subroutine is called by getattr and open. +; This subroutine looks for file name and returns NULL or pointer to file info record. +lookup_file_name: + mov ebp, [esp+8] ; hPlugin + mov esi, [esp+12] ; filename + lea edi, [ebp+handle_common.root.subfolders] + xor eax, eax +; KFar operates with absolute names, skip first '/' + cmp byte [esi], '/' + jnz .notfound + inc esi +.mainloop: +; get next component of name + push -1 + pop ecx +@@: + inc ecx + cmp byte [esi+ecx], '/' + jz @f + cmp byte [esi+ecx], 0 + jnz @b +@@: +; esi->component, ecx=length +; scan for required item in subfolders list + push -1 + mov eax, [edi] ; .subfolders +.scan1: + test eax, eax + jz .notfound1 + add eax, ebp + cmp [eax+file_common.namelen], ecx + jnz .cont1 + push ecx esi edi + mov edi, [eax+file_common.name] + repz cmpsb + pop edi esi ecx + jz .found1 +.cont1: + mov eax, [eax+file_common.next] + jmp .scan1 +.notfound1: + pop edx +; if this is last component in file name, scan in subfiles list + cmp byte [esi+ecx], al + jnz .notfound + inc edx + jnz .notfound + mov eax, [edi+8] ; .subfiles + push edx + jmp .scan1 +.found1: + pop edi +; item is found, go to next component + lea edi, [eax+file_common.subfolders] + lea esi, [esi+ecx+1] + cmp byte [esi-1], 0 + jnz .mainloop +; this was the last component +.notfound: + ret + +; Memory streams handling. +; Archive handlers create memory stream for small files: +; size of which is not greater than (free RAM size)/4 and +; not greater than following constant... +;LIMIT_FOR_MEM_STREAM = 2*1024*1024 +; ...if it is defined. Now the definition is commented: +; if user has many physical memory, why not to use it? + +virtual at 0 +mem_stream: +.type dd ? ; type_mem_stream +.size dd ? +.pos dd ? +.buf: +end virtual + +; unsigned __stdcall read(ebx = HANDLE hFile, void* buf, unsigned size); +read_mem_stream: + mov eax, [esp+12] + mov ecx, [ebx+mem_stream.size] + sub ecx, [ebx+mem_stream.pos] + jnc @f + xor ecx, ecx +@@: + cmp eax, ecx + jb @f + mov eax, ecx +@@: + mov ecx, eax + lea esi, [ebx+mem_stream.buf] + add esi, [ebx+mem_stream.pos] + add [ebx+mem_stream.pos], eax + mov edi, [esp+8] + mov edx, ecx + shr ecx, 2 + rep movsd + mov ecx, edx + and ecx, 3 + rep movsb + ret 12 + +; void __stdcall setpos(ebx = HANDLE hFile, __int64 pos); +setpos_mem_stream: + mov eax, [esp+8] + mov [ebx+mem_stream.pos], eax + ret 12 + +; void __stdcall close(ebx = HANDLE hFile); +close_mem_stream: + mov ecx, ebx + call [pgfree] + ret 4 + +; Allocate handle for file +; esi -> handle table, ecx = size of handle +alloc_handle: +; Handle table is L2-list of allocated pages. +; Scan for free entry + mov edx, esi +@@: + mov edx, [edx] + cmp edx, esi + jz .alloc_new + mov eax, [edx+8] ; head of L1-list of free entries + test eax, eax ; has free entry? + jz @b +; we have found allocated page with free entry; allocate entry and return + inc dword [edx+12] ; number of busy entries + push dword [eax] + pop dword [edx+8] +.ret: + ret +.alloc_new: +; no free pages; get new page and initialize + push ecx + mov ecx, 0x1000 + call [pgalloc] + pop ecx + test eax, eax + jz .ret +; insert new page to start of L2-list + mov edx, [esi] + mov [eax], edx + mov [esi], eax + mov [eax+4], esi + mov [edx+4], eax + mov dword [eax+12], 1 ; 1 allocated entry +; initialize list of free entries + lea edx, [eax+16] + push edx ; save return value + add edx, ecx + mov [eax+8], edx + add eax, 0x1000 +@@: + mov esi, edx + add edx, ecx + mov [esi], edx + cmp edx, eax + jb @b + and dword [esi], 0 + pop eax + ret + +; Free handle allocated in previous procedure +; esi = handle +free_handle: + mov ecx, esi + and ecx, not 0xFFF ; get page +; add entry to head of L1-list of free entries + mov eax, [ecx+8] + mov [esi], eax + mov [ecx+8], esi + dec dword [ecx+12] ; decrement number of allocated entries + jnz .ret +; delete page from common L2-list + mov eax, [ecx] + mov edx, [ecx+4] + mov [eax+4], edx + mov [edx], eax +; free page + call [pgfree] +.ret: + ret + +; Ask user to enter password. +; Out: ZF set <=> user pressed Esc +; 'password_ansi', 'password_unicode', 'password_size' filled +query_password: + cmp [bPasswordDefined], 0 + jnz .ret + mov edi, password_data + mov eax, password_maxlen + stosd ; maximum length + xor eax, eax + stosd ; start of visible part + stosd ; position of cursor + stosb ; initial state: empty string + mov eax, [cur_console_size] + mov eax, [eax] ; get current console width + sub eax, 12 + mov edi, password_dlg + mov [edi+password_dlg.width-password_dlg], eax + dec eax + dec eax + mov [edi+password_dlg.width1-password_dlg], eax + mov [edi+password_dlg.width2-password_dlg], eax + push edi + call [DialogBox] + inc eax + jz .ret +; convert ANSI-cp866 to UNICODE string; also calculate 'password_size' + mov esi, password_ansi + mov edi, password_unicode + or [password_size], -1 +.cvt: + inc [password_size] + lodsb + mov ah, 0 +; 0x00-0x7F - trivial map + cmp al, 0x80 + jb .symb +; 0x80-0xAF -> 0x410-0x43F + cmp al, 0xB0 + jae @f + add ax, 0x410-0x80 + jmp .symb +@@: +; 0xE0-0xEF -> 0x440-0x44F + cmp al, 0xE0 + jb .unk + cmp al, 0xF0 + jae @f + add ax, 0x440-0xE0 + jmp .symb +@@: +; 0xF0 -> 0x401 +; 0xF1 -> 0x451 + cmp al, 'Ё' + jz .yo1 + cmp al, 'ё' + jz .yo2 +.unk: + mov al, '_' + jmp .symb +.yo1: + mov ax, 0x401 + jmp .symb +.yo2: + mov ax, 0x451 +.symb: + stosw + test al, al + jnz .cvt + inc [bPasswordDefined] ; clears ZF flag +.ret: + ret + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;; API for other programs ;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; void* __stdcall deflate_unpack(void* packed_data, unsigned* pLength) +deflate_unpack: + push dword [esp+8] + push esp + push deflate_unpack_cb + call deflate_unpack2 + ret 8 + +deflate_unpack_cb: + mov edx, [esp+4] + push edx + mov edx, [edx+12] + mov edx, [edx] + mov eax, [esp+8+4] + mov [eax], edx + pop edx + xor eax, eax + xchg eax, [edx+8] + ret 8 + +; void* __stdcall deflate_unpack2(void* get_next_chunk, void* parameter, unsigned* pUnpackedLength) +; void* __stdcall get_next_chunk(void* parameter, unsigned* pLength) +deflate_unpack2: + pusha + mov ecx, 0x11000 + call mypgalloc + test eax, eax + jz .ret + or dword [eax+streamInfo.fullSize], -1 + or dword [eax+streamInfo.fullSize+4], -1 + and dword [eax+streamInfo.bufSize], 0 + mov dword [eax+streamInfo.fillBuf], .fillBuf + mov edx, [esp+32+4] + mov [eax+streamInfo.size], edx + mov edx, [esp+32+8] + mov [eax+streamInfo.size+4], edx + mov [eax+streamInfo.size+8+deflate_decoder.inStream], eax + add eax, streamInfo.size+8 + lea edi, [eax+deflate_decoder.size] + mov [eax+streamInfo.bufPtr], edi + mov ebp, eax + call deflate_init_decoder + xor edx, edx + mov ecx, 10000h +.loop: + push @f + pushad + mov [_esp], esp + mov [_ebp], ebp + mov [error_proc], .error + mov ecx, 10000h + jmp [eax+streamInfo.fillBuf] +@@: + push SF_SYS_MISC + pop eax + push SSF_MEM_REALLOC + pop ebx + int 0x40 + test eax, eax + jz .nomem + mov edx, eax + mov eax, ebp + mov esi, edi + push edi + lea edi, [edx+ecx-0x10000] + push ecx + mov ecx, 0x10000/4 + rep movsd + pop ecx + pop edi + add ecx, 0x10000 + jmp .loop +.error: + pop eax + push edi + popad + pop eax + mov eax, ebp + lea esi, [eax+deflate_decoder.size] + sub ecx, 0x10000 + sub edi, esi + add ecx, edi + mov eax, [esp+32+12] + test eax, eax + jz @f + mov [eax], ecx +@@: + test ecx, ecx + jnz @f + inc ecx +@@: + push SF_SYS_MISC + pop eax + push SSF_MEM_REALLOC + pop ebx + int 0x40 + test eax, eax + jz .nomem + sub ecx, edi + mov edx, edi + lea edi, [eax+ecx] + mov ecx, edx + shr ecx, 2 + rep movsd + mov ecx, edx + and ecx, 3 + rep movsb + push eax + push SF_SYS_MISC + pop eax + push SSF_MEM_FREE + pop ebx + lea ecx, [ebp-streamInfo.size-8] + int 40h + pop eax + jmp .ret +.nomem: + push SF_SYS_MISC + pop eax + push SSF_MEM_FREE + pop ebx + test edx, edx + jz @f + mov ecx, edx + push eax + int 0x40 + pop eax +@@: + lea ecx, [ebp-streamInfo.size-8] + int 0x40 + xor eax, eax +.ret: + mov [esp+28], eax + popa + ret 12 +.fillBuf: + push eax + push eax + push esp + push dword [eax+streamInfo.size+4] + call dword [eax+streamInfo.size] + pop edx + pop ebp + mov [ebp+streamInfo.bufPtr], eax + and [ebp+streamInfo.bufDataLen], 0 + test eax, eax + jz @f + mov [ebp+streamInfo.bufDataLen], edx +@@: + popad + ret + +mypgalloc: + push SF_SYS_MISC + pop eax + push SSF_MEM_ALLOC + pop ebx + int 0x40 + ret + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;; Initialized data ;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; export table +align 4 +EXPORTS: + dd aVersion, 3 + dd aPluginLoad, plugin_load + dd aOpenFilePlugin,OpenFilePlugin + dd aClosePlugin, ClosePlugin + dd aReadFolder, ReadFolder + dd aSetFolder, SetFolder + dd aGetFiles, GetFiles + dd aGetOpenPluginInfo, GetOpenPluginInfo + dd aGetattr, mygetattr + dd aOpen, myopen + dd aRead, myread + dd aSetpos, mysetpos + dd aClose, myclose + dd aDeflateUnpack, deflate_unpack + dd aDeflateUnpack2,deflate_unpack2 + dd adeflateInit, deflateInit + dd adeflateInit2, deflateInit2 + dd adeflateReset, deflateReset + dd adeflate, deflate + dd adeflateEnd, deflateEnd + dd azError, zError + dd acalc_crc32, calc_crc32 + dd 0 + +; exported names +aVersion db 'version',0 +aPluginLoad db 'plugin_load',0 +aOpenFilePlugin db 'OpenFilePlugin',0 +aClosePlugin db 'ClosePlugin',0 +aReadFolder db 'ReadFolder',0 +aSetFolder db 'SetFolder',0 +aGetFiles db 'GetFiles',0 +aGetOpenPluginInfo db 'GetOpenPluginInfo',0 +aGetattr db 'getattr',0 +aOpen db 'open',0 +aRead db 'read',0 +aSetpos db 'setpos',0 +aClose db 'close',0 +aDeflateUnpack db 'deflate_unpack',0 +aDeflateUnpack2 db 'deflate_unpack2',0 +adeflateInit db 'deflateInit',0 +adeflateInit2 db 'deflateInit2',0 +adeflateReset db 'deflateReset',0 +adeflate db 'deflate',0 +adeflateEnd db 'deflateEnd',0 +azError db 'zError',0 +acalc_crc32 db 'calc_crc32',0 + +; common strings +if lang eq ru_RU +aContinue db 'Продолжить',0 +aCancel db 'Отмена',0 +aHeaderError db 'Ошибка в заголовке архива',0 +aReadError db 'Ошибка чтения',0 +aNoFreeRam db 'Недостаточно свободной оперативной памяти',0 +aEncodingProblem db 'Проблема с кодировкой',0 +aEncodingProblem_str db 'Имена некоторых файлов в архиве содержат символы,',0 +.2 db 'не представимые в кодировке cp866.',0 +.3 db 'Эти символы будут заменены на подчёркивания.',0 +aEnterPassword db 'Введите пароль:',0 +aEnterPasswordLen = $ - aEnterPassword - 1 +aEnterPasswordTitle db 'Ввод пароля',0 +aArchiveDataError db 'Ошибка в данных архива',0 +aArchiveDataErrorPass db 'Ошибка в данных архива или неверный пароль',0 +aChangePass db 'Ввести пароль',0 +aNameTooLong db 'Слишком длинное имя',0 +aCannotOpenFile db 'Не могу открыть файл',0 +else +aContinue db 'Continue',0 +aCancel db 'Cancel',0 +aHeaderError db 'Invalid archive header',0 +aReadError db 'Read error',0 +aNoFreeRam db 'There is not enough of free RAM',0 +aEncodingProblem db 'Encoding problem',0 +aEncodingProblem_str db 'The names of some files in the archive contain',0 +.2 db 'characters which can not be represented in cp866.',0 +.3 db 'Such characters will be replaced to underscores.',0 +aEnterPassword db 'Enter password:',0 +aEnterPasswordLen = $ - aEnterPassword - 1 +aEnterPasswordTitle db 'Get password',0 +aArchiveDataError db 'Error in archive data',0 +aArchiveDataErrorPass db 'Error in archive data or incorrect password',0 +aChangePass db 'Enter password',0 +aNameTooLong db 'Name is too long',0 +aCannotOpenFile db 'Cannot open file',0 +end if + +; kfar_arc supports many archive types. +; OpenFilePlugin looks for supported archive signature and gives control +; to concrete handler if found. +; Other functions just determine type of opened archive and jump to corresponding handler. +type_mem_stream = 0 ; memory stream - for file handles (returned from 'open') +type_7z = 1 +type_zip = 2 + +; archive functions (types start from type_7z) +align 4 +ClosePluginTable: + dd close_7z + dd close_zip +getattrTable: + dd getattr_7z + dd getattr_zip +openTable: + dd open_file_7z + dd open_file_zip +basesizes: + dd handle_7z.basesize, file_in_7z.size + dd handle_zip.basesize, file_in_zip.size + +; file functions (types start from type_mem_stream) +readTable: + dd read_mem_stream + dd read_7z + dd read_zip +setposTable: + dd setpos_mem_stream + dd setpos_7z + dd setpos_zip +closeTable: + dd close_mem_stream + dd close_file_7z + dd close_file_zip + +; pointers for SayErr and Message +ContinueBtn dd aContinue +HeaderError_ptr dd aHeaderError +aReadError_ptr dd aReadError +aNoFreeRam_ptr dd aNoFreeRam +aEncodingProblem_str_ptr: + dd aEncodingProblem_str + dd aEncodingProblem_str.2 + dd aEncodingProblem_str.3 +aNameTooLong_ptr dd aNameTooLong +aArchiveDataError_ptr dd aArchiveDataError +aArchiveDataErrorPass_ptr dd aArchiveDataErrorPass +CancelPassBtn dd aCancel + dd aChangePass + +; "enter password" dialog for KFar +password_dlg: + dd 1 ; use standard dialog colors + dd -1 ; center window by x + dd -1 ; center window by y +.width dd ? ; width (will be filled according to current console width) + dd 2 ; height + dd 4, 2 ; border size + dd aEnterPasswordTitle ; title + dd ? ; colors (will be set by KFar) + dd 0 ; used internally by dialog manager, ignored + dd 0, 0 ; reserved for DlgProc + dd 2 ; 2 controls +; the string "enter password" + dd 1 ; type: static + dd 1,0 ; upper-left position +.width1 dd ?,0 ; bottom-right position + dd aEnterPassword ; data + dd 0 ; flags +; editbox for password + dd 3 ; type: edit + dd 1,1 ; upper-left position +.width2 dd ?,0 ; bottom-right position + dd password_data ; data + dd 2Ch ; flags + +IncludeIGlobals + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;; Uninitialized data ;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +purge data ;used in 'macros.inc' +purge section ;used in 'macros.inc' + +section '.udata' data readable writable align 16 +kfar_info dd ? +crc_table rd 256 +_esp dd ? +_ebp dd ? +bufsize dd ? +bufptr dd ? +bufend dd ? +buffer rb 1024 +inStream dd ? +hOut dd ? +.allocated dd ? + +error_proc dd ? +clear_proc dd ? + +; import from kfar +open2 dd ? +filesize dd ? +read dd ? +seek dd ? +close dd ? +pgalloc dd ? +pgrealloc dd ? +pgfree dd ? +getfreemem dd ? +DialogBox dd ? +SayErr dd ? +Message dd ? +cur_console_size dd ? + +; data for editbox in kfar dialog +password_maxlen = 512 +password_data: +.maxlen dd ? +.pos dd ? +.start dd ? +password_ansi rb password_maxlen+1 +bPasswordDefined db ? + +; converted password +password_unicode rw password_maxlen+1 +password_size dd ? + +IncludeUGlobals + +bWasWarning db ? diff --git a/programs/fs/kfar/trunk/kfar_arc/kglobals.inc b/programs/fs/kfar/kfar_arc/kglobals.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/kglobals.inc rename to programs/fs/kfar/kfar_arc/kglobals.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/lzma.inc b/programs/fs/kfar/kfar_arc/lzma.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/lzma.inc rename to programs/fs/kfar/kfar_arc/lzma.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/ppmd.inc b/programs/fs/kfar/kfar_arc/ppmd.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/ppmd.inc rename to programs/fs/kfar/kfar_arc/ppmd.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/sha256.inc b/programs/fs/kfar/kfar_arc/sha256.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/sha256.inc rename to programs/fs/kfar/kfar_arc/sha256.inc diff --git a/programs/fs/kfar/trunk/kfar_arc/zip.inc b/programs/fs/kfar/kfar_arc/zip.inc similarity index 100% rename from programs/fs/kfar/trunk/kfar_arc/zip.inc rename to programs/fs/kfar/kfar_arc/zip.inc diff --git a/programs/fs/kfar/trunk/kglobals.inc b/programs/fs/kfar/kglobals.inc similarity index 100% rename from programs/fs/kfar/trunk/kglobals.inc rename to programs/fs/kfar/kglobals.inc diff --git a/programs/fs/kfar/trunk/search.inc b/programs/fs/kfar/search.inc similarity index 100% rename from programs/fs/kfar/trunk/search.inc rename to programs/fs/kfar/search.inc diff --git a/programs/fs/kfar/trunk/sort.inc b/programs/fs/kfar/sort.inc similarity index 100% rename from programs/fs/kfar/trunk/sort.inc rename to programs/fs/kfar/sort.inc diff --git a/programs/fs/kfar/trunk/tools.inc b/programs/fs/kfar/tools.inc similarity index 100% rename from programs/fs/kfar/trunk/tools.inc rename to programs/fs/kfar/tools.inc diff --git a/programs/fs/kfar/trunk/viewer.inc b/programs/fs/kfar/viewer.inc similarity index 100% rename from programs/fs/kfar/trunk/viewer.inc rename to programs/fs/kfar/viewer.inc diff --git a/programs/fs/kfar/trunk/zlib/adler32.asm b/programs/fs/kfar/zlib/adler32.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/adler32.asm rename to programs/fs/kfar/zlib/adler32.asm diff --git a/programs/fs/kfar/trunk/zlib/build.bat b/programs/fs/kfar/zlib/build.bat similarity index 100% rename from programs/fs/kfar/trunk/zlib/build.bat rename to programs/fs/kfar/zlib/build.bat diff --git a/programs/fs/kfar/trunk/zlib/crc32.asm b/programs/fs/kfar/zlib/crc32.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/crc32.asm rename to programs/fs/kfar/zlib/crc32.asm diff --git a/programs/fs/kfar/trunk/zlib/debug.inc b/programs/fs/kfar/zlib/debug.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/debug.inc rename to programs/fs/kfar/zlib/debug.inc diff --git a/programs/fs/kfar/trunk/zlib/deflate.asm b/programs/fs/kfar/zlib/deflate.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/deflate.asm rename to programs/fs/kfar/zlib/deflate.asm diff --git a/programs/fs/kfar/trunk/zlib/deflate.inc b/programs/fs/kfar/zlib/deflate.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/deflate.inc rename to programs/fs/kfar/zlib/deflate.inc diff --git a/programs/fs/kfar/trunk/zlib/example1.asm b/programs/fs/kfar/zlib/example1.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/example1.asm rename to programs/fs/kfar/zlib/example1.asm diff --git a/programs/fs/kfar/trunk/zlib/trees.asm b/programs/fs/kfar/zlib/trees.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/trees.asm rename to programs/fs/kfar/zlib/trees.asm diff --git a/programs/fs/kfar/trunk/zlib/trees.inc b/programs/fs/kfar/zlib/trees.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/trees.inc rename to programs/fs/kfar/zlib/trees.inc diff --git a/programs/fs/kfar/trunk/zlib/zconf.inc b/programs/fs/kfar/zlib/zconf.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/zconf.inc rename to programs/fs/kfar/zlib/zconf.inc diff --git a/programs/fs/kfar/trunk/zlib/zlib.asm b/programs/fs/kfar/zlib/zlib.asm similarity index 89% rename from programs/fs/kfar/trunk/zlib/zlib.asm rename to programs/fs/kfar/zlib/zlib.asm index d86be4b57..00b29361b 100644 --- a/programs/fs/kfar/trunk/zlib/zlib.asm +++ b/programs/fs/kfar/zlib/zlib.asm @@ -1,170 +1,171 @@ - -include '../../../../proc32.inc' -include '../../../../macros.inc' -include '../../../../KOSfuncs.inc' - -FASTEST equ 0 -GEN_TREES_H equ 0 -DEBUG equ 0 -DYNAMIC_CRC_TABLE equ 1 -Z_SOLO equ 0 - -; define NO_GZIP when compiling if you want to disable gzip header and -; trailer creation by deflate(). NO_GZIP would be used to avoid linking in -; the crc code when it is not needed. For shared libraries, gzip encoding -; should be left enabled. -GZIP equ 1 - -macro zlib_debug fmt,p1 -{ -if DEBUG eq 1 - zlib_assert fmt,p1 -end if -} - -macro zlib_assert fmt,p1 -{ - local .end_t - local .m_fmt -pushf - jmp .end_t - .m_fmt db fmt,13,10,0 -align 4 - .end_t: -if p1 eq - stdcall dbg_print,0,.m_fmt -else - stdcall str_format_dbg, buf_param,.m_fmt,p1 -end if -popf -} - -include 'zlib.inc' -include 'deflate.inc' -include 'zutil.asm' -;include '../kfar_arc/crc.inc' -include 'crc32.asm' -include 'adler32.asm' -include 'trees.asm' -include 'deflate.asm' - -align 4 -buf_param rb 80 - -align 4 -proc dbg_print, fun:dword, mes:dword -pushad - mov eax,SF_BOARD - mov ebx,SSF_DEBUG_WRITE - - mov esi,[fun] - cmp esi,0 - je .end0 - @@: - mov cl,byte[esi] - int 0x40 - inc esi - cmp byte[esi],0 - jne @b - mov cl,':' - int 0x40 - mov cl,' ' - int 0x40 - .end0: - mov esi,[mes] - cmp esi,0 - je .end_f - @@: - mov cl,byte[esi] - cmp cl,0 - je .end_f - int 0x40 - inc esi - jmp @b - .end_f: -popad - ret -endp - -align 4 -proc str_format_dbg, buf:dword, fmt:dword, p1:dword -pushad - mov esi,[fmt] - mov edi,[buf] - mov ecx,80-1 - .cycle0: - lodsb - cmp al,'%' - jne .no_param - lodsb - dec ecx - cmp al,0 - je .cycle0end - cmp al,'d' - je @f - cmp al,'u' - je @f - cmp al,'l' - je .end1 - jmp .end0 - .end1: ;%lu %lx - lodsb - dec ecx - cmp al,'u' - jne .end0 - @@: - mov eax,[p1] - stdcall convert_int_to_str,ecx - xor al,al - repne scasb - dec edi - .end0: - loop .cycle0 - .no_param: - stosb - cmp al,0 - je .cycle0end - loop .cycle0 - .cycle0end: - xor al,al - stosb - stdcall dbg_print,0,[buf] -popad - ret -endp - -;input: -; eax - ╤З╨╕╤Б╨╗╨╛ -; edi - ╨▒╤Г╤Д╨╡╤А ╨┤╨╗╤П ╤Б╤В╤А╨╛╨║╨╕ -; len - ╨┤╨╗╨╕╨╜╨╜╨░ ╨▒╤Г╤Д╨╡╤А╨░ -;output: -align 4 -proc convert_int_to_str, len:dword -pushad - mov esi,[len] - add esi,edi - dec esi - call .str -popad - ret -endp - -align 4 -.str: - mov ecx,0x0a - cmp eax,ecx - jb @f - xor edx,edx - div ecx - push edx - call .str - pop eax - @@: - cmp edi,esi - jge @f - or al,0x30 - stosb - mov byte[edi],0 - @@: - ret - +; SPDX-License-Identifier: NOASSERTION +; + +include '../../../proc32.inc' +include '../../../macros.inc' +include '../../../KOSfuncs.inc' + +FASTEST equ 0 +GEN_TREES_H equ 0 +DEBUG equ 0 +DYNAMIC_CRC_TABLE equ 1 +Z_SOLO equ 0 + +; define NO_GZIP when compiling if you want to disable gzip header and +; trailer creation by deflate(). NO_GZIP would be used to avoid linking in +; the crc code when it is not needed. For shared libraries, gzip encoding +; should be left enabled. +GZIP equ 1 + +macro zlib_debug fmt,p1 +{ +if DEBUG eq 1 + zlib_assert fmt,p1 +end if +} + +macro zlib_assert fmt,p1 +{ + local .end_t + local .m_fmt +pushf + jmp .end_t + .m_fmt db fmt,13,10,0 +align 4 + .end_t: +if p1 eq + stdcall dbg_print,0,.m_fmt +else + stdcall str_format_dbg, buf_param,.m_fmt,p1 +end if +popf +} + +include 'zlib.inc' +include 'deflate.inc' +include 'zutil.asm' +;include '../kfar_arc/crc.inc' +include 'crc32.asm' +include 'adler32.asm' +include 'trees.asm' +include 'deflate.asm' + +align 4 +buf_param rb 80 + +align 4 +proc dbg_print, fun:dword, mes:dword +pushad + mov eax,SF_BOARD + mov ebx,SSF_DEBUG_WRITE + + mov esi,[fun] + cmp esi,0 + je .end0 + @@: + mov cl,byte[esi] + int 0x40 + inc esi + cmp byte[esi],0 + jne @b + mov cl,':' + int 0x40 + mov cl,' ' + int 0x40 + .end0: + mov esi,[mes] + cmp esi,0 + je .end_f + @@: + mov cl,byte[esi] + cmp cl,0 + je .end_f + int 0x40 + inc esi + jmp @b + .end_f: +popad + ret +endp + +align 4 +proc str_format_dbg, buf:dword, fmt:dword, p1:dword +pushad + mov esi,[fmt] + mov edi,[buf] + mov ecx,80-1 + .cycle0: + lodsb + cmp al,'%' + jne .no_param + lodsb + dec ecx + cmp al,0 + je .cycle0end + cmp al,'d' + je @f + cmp al,'u' + je @f + cmp al,'l' + je .end1 + jmp .end0 + .end1: ;%lu %lx + lodsb + dec ecx + cmp al,'u' + jne .end0 + @@: + mov eax,[p1] + stdcall convert_int_to_str,ecx + xor al,al + repne scasb + dec edi + .end0: + loop .cycle0 + .no_param: + stosb + cmp al,0 + je .cycle0end + loop .cycle0 + .cycle0end: + xor al,al + stosb + stdcall dbg_print,0,[buf] +popad + ret +endp + +;input: +; eax - ╤З╨╕╤Б╨╗╨╛ +; edi - ╨▒╤Г╤Д╨╡╤А ╨┤╨╗╤П ╤Б╤В╤А╨╛╨║╨╕ +; len - ╨┤╨╗╨╕╨╜╨╜╨░ ╨▒╤Г╤Д╨╡╤А╨░ +;output: +align 4 +proc convert_int_to_str, len:dword +pushad + mov esi,[len] + add esi,edi + dec esi + call .str +popad + ret +endp + +align 4 +.str: + mov ecx,0x0a + cmp eax,ecx + jb @f + xor edx,edx + div ecx + push edx + call .str + pop eax + @@: + cmp edi,esi + jge @f + or al,0x30 + stosb + mov byte[edi],0 + @@: + ret diff --git a/programs/fs/kfar/trunk/zlib/zlib.inc b/programs/fs/kfar/zlib/zlib.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/zlib.inc rename to programs/fs/kfar/zlib/zlib.inc diff --git a/programs/fs/kfar/trunk/zlib/zlib.txt b/programs/fs/kfar/zlib/zlib.txt similarity index 100% rename from programs/fs/kfar/trunk/zlib/zlib.txt rename to programs/fs/kfar/zlib/zlib.txt diff --git a/programs/fs/kfar/trunk/zlib/zutil.asm b/programs/fs/kfar/zlib/zutil.asm similarity index 100% rename from programs/fs/kfar/trunk/zlib/zutil.asm rename to programs/fs/kfar/zlib/zutil.asm diff --git a/programs/fs/kfar/trunk/zlib/zutil.inc b/programs/fs/kfar/zlib/zutil.inc similarity index 100% rename from programs/fs/kfar/trunk/zlib/zutil.inc rename to programs/fs/kfar/zlib/zutil.inc diff --git a/programs/games/nu_pogodi/build.bat b/programs/games/nu_pogodi/build.bat index 61149f642..775871b39 100644 --- a/programs/games/nu_pogodi/build.bat +++ b/programs/games/nu_pogodi/build.bat @@ -1,7 +1,7 @@ if not exist bin mkdir bin -if not exist bin\font8x9.bmp @copy ..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp +if not exist bin\font8x9.bmp @copy ..\..\..\fs\kfar\font8x9.bmp bin\font8x9.bmp @copy *.png bin\*.png @copy *.ini bin\*.ini @fasm.exe -m 16384 nu_pogod.asm bin\nu_pogod.kex @kpack bin\nu_pogod.kex -pause \ No newline at end of file +pause diff --git a/programs/media/img_transform/img_transform.asm b/programs/media/img_transform/img_transform.asm index 65b79af9e..2634a6617 100644 --- a/programs/media/img_transform/img_transform.asm +++ b/programs/media/img_transform/img_transform.asm @@ -1,3 +1,8 @@ +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + use32 org 0 db 'MENUET01' @@ -50,7 +55,7 @@ start: stdcall [buf2d_create], buf_0 ;создание буфера - include_image_file '../../../programs/fs/kfar/trunk/font6x9.bmp', image_data_toolbar, buf_font.w,buf_font.h + include_image_file '../../../programs/fs/kfar/font6x9.bmp', image_data_toolbar, buf_font.w,buf_font.h stdcall [buf2d_create_f_img], buf_font,[image_data_toolbar] ;создаем буфер stdcall mem.Free,[image_data_toolbar] ;освобождаем память stdcall [buf2d_conv_24_to_8], buf_font,1 ;делаем буфер прозрачности 8 бит diff --git a/programs/media/log_el/trunk/build_ru.bat b/programs/media/log_el/trunk/build_ru.bat index 9a104dba2..b8dc3ded3 100644 --- a/programs/media/log_el/trunk/build_ru.bat +++ b/programs/media/log_el/trunk/build_ru.bat @@ -1,5 +1,5 @@ if not exist bin mkdir bin -if not exist bin\font6x9.bmp @copy ..\..\..\fs\kfar\trunk\font6x9.bmp bin\font6x9.bmp +if not exist bin\font6x9.bmp @copy ..\..\..\fs\kfar\font6x9.bmp bin\font6x9.bmp @copy *.png bin\*.png @copy *.txt bin\*.txt @fasm.exe -m 16384 log_el.asm bin\log_el.kex diff --git a/programs/other/cnc_control/cnc_control.asm b/programs/other/cnc_control/cnc_control.asm index 0f4f9fbb8..5cc016dee 100644 --- a/programs/other/cnc_control/cnc_control.asm +++ b/programs/other/cnc_control/cnc_control.asm @@ -1,1075 +1,1079 @@ -;CNC CONTROL -;Igor Afanasyev (aka IgorA) and Sergey Efremenkov (aka theonlymirage), 2020 - -;02.10.18 - Only prototype UI -;08.10.18 - Add ComboBox (Button + KMenu), small text - -format binary as "" -use32 - org 0 - db 'MENUET01' - dd 1,start,i_end,mem,stacktop,file_name,sys_path - -include '../../macros.inc' -include '../../proc32.inc' -include '../../KOSfuncs.inc' -include '../../load_img.inc' -include '../../load_lib.mac' -include '../../develop/libraries/libs-dev/libimg/libimg.inc' -include '../../develop/libraries/box_lib/trunk/box_lib.mac' -include 'lang.inc' -include 'cnc_control.inc' -include '../../develop/info3ds/info_fun_float.inc' - -KMENUITEM_NORMAL equ 0 -KMENUITEM_SUBMENU equ 1 -KMENUITEM_SEPARATOR equ 2 - -@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load -caption db 'CNC Control 18.12.20',0 ;подпись окна - -run_file_70 FileInfoBlock - -offs_last_timer dd 0 ;последний сдвиг показаный в функции таймера - -IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3 -image_data_toolbar dd 0 ;указатель на временную память. для нужен преобразования изображения -icon_tl_sys dd 0 ;указатель на память для хранения системных иконок -icon_toolbar dd 0 ;указатель на память для хранения иконок объектов - -align 4 -start: - ;--- copy cmd line --- - mov esi,file_name - mov edi,openfile_path -@@: - lodsd - or eax,eax - jz @f ;выход, если 0 - stosd - jmp @b -@@: - stosd - - load_libraries l_libs_start,l_libs_end - ;проверка на сколько удачно загузилась библиотека - mov ebp,lib_0 - cmp dword [ebp+ll_struc_size-4],0 - jz @f - mcall SF_TERMINATE_PROCESS - @@: - mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors - mcall SF_SET_EVENTS_MASK,0xC0000027 - stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога - - stdcall [buf2d_create], buf_0 ;создание буфера - - ;шрифт делаем до создания панели (для экономии указателя image_data_toolbar) - include_image_file '..\..\fs\kfar\trunk\font6x9.bmp', image_data_toolbar, buf_1.w,buf_1.h - stdcall [buf2d_create_f_img], buf_1,[image_data_toolbar] ;создаем буфер - stdcall mem.Free,[image_data_toolbar] ;освобождаем память - stdcall [buf2d_conv_24_to_8], buf_1,1 ;делаем буфер прозрачности 8 бит - stdcall [buf2d_convert_text_matrix], buf_1 - mov eax,[buf_1.h] - shr eax,8 - mov [font_h],eax - - include_image_file 'toolbar.png', image_data_toolbar - - ;*** установка времени для таймера - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov [last_time],eax - - ;call but_new_file - option_boxes_set_sys_color sc,opt_grlist1 - - ;progress bar - mov [pb.left], dword 50 - mov [pb.top], dword 30 - mov [pb.width], dword 350 - mov [pb.height], dword 17 - mov [pb.max], dword 100;599 - mov [pb.min], dword 0 ;-397 - mov [pb.value], dword 0 ;-397 - mov [pb.back_color], dword 00C8D0D4h - mov [pb.progress_color], dword 8072B7EBh - mov [pb.frame_color], dword 00406175h - - ;port menu - stdcall [kmenu_init], sc ;kmenu initialisation - ;stdcall [ksubmenu_new] - ;mov [main_menu], eax - - stdcall [ksubmenu_new] - mov [port_menu], eax - stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_COMport, 110 - stdcall [ksubmenu_add], [port_menu], eax - stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_USBport, 111 - stdcall [ksubmenu_add], [port_menu], eax - ;stdcall [kmenuitem_new], KMENUITEM_SEPARATOR, 0, 0 - ;stdcall [ksubmenu_add], [port_menu], eax - ;stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_OTHERport, 112 - ;stdcall [ksubmenu_add], [port_menu], eax - stdcall [kmenuitem_new], KMENUITEM_SUBMENU, sz_PortMenu, [port_menu] - ;stdcall [ksubmenu_add], [main_menu], eax - - ;open file from cmd line - cmp dword[openfile_path],0 - je @f - call but_open_file.no_dlg - @@: - -align 4 -red_win: - call draw_window - -align 4 -still: - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov ebx,[last_time] - add ebx,10 ;задержка - cmp ebx,eax - jge @f - mov ebx,eax - @@: - sub ebx,eax - mcall SF_WAIT_EVENT_TIMEOUT - cmp eax,0 - jne @f - call timer_funct - jmp still - @@: - - cmp al,1 - jz red_win - cmp al,2 - jz key - cmp al,3 - jz button - cmp al,6 - jne @f - mcall SF_THREAD_INFO,procinfo,-1 - cmp ax,word[procinfo.window_stack_position] - jne @f ;окно не активно - call mouse - @@: - jmp still - -align 4 -mouse: - stdcall [option_box_mouse], opt_grlist1 - stdcall [edit_box_mouse], editFileName - stdcall [edit_box_mouse], editCommand - stdcall [kmainmenu_dispatch_cursorevent], [port_menu] ;[main_menu] - - push eax ebx ecx - mcall SF_MOUSE_GET,SSF_BUTTON_EXT - bt eax,8 - jnc @f - ;mouse l. but. press - call mouse_left_d - jmp .end_l - @@: - bt eax,16 - jnc .end_l - ;mouse l. but. up - call mouse_left_u - ;jmp .end_l - .end_l: - - - call buf_get_mouse_coord - cmp eax,-1 - je .end0 - shl eax,1 - sub eax,[buf_0.w] - sar eax,1 - mov [mouse_prop_x],eax - mov ecx,ObjData - shl ebx,1 - sub ebx,[buf_0.h] - sar ebx,1 - mov [mouse_prop_y],ebx - - mcall SF_MOUSE_GET,SSF_SCROLL_DATA - test ax,ax - jz .end0 - finit - fld qword[zoom_plus] - fld1 - fsubp - fld st0 ;for Y coord - - ;for X coord - fild dword[mouse_prop_x] - fmulp st1,st0 - - mov ebx,eax - test ax,0x8000 - jnz .decr - ;увеличение масштаба - fchs - fild dword[ecx+Figure.MCentrX] ;add old value - fmul qword[zoom_plus] - faddp - - fld qword[ecx+Figure.MScale] - fmul qword[zoom_plus] - ;if (Figure.MScale>16.0) - ;... - jmp @f - .decr: - ;уменьшение масштаба - fild dword[ecx+Figure.MCentrX] ;add old value - fdiv qword[zoom_plus] - faddp - - fld qword[ecx+Figure.MScale] - fdiv qword[zoom_plus] - fld1 - fcomp - fstsw ax - sahf - jbe @f - ;if (Figure.MScale<1.0) - ffree st0 - fincstp - ffree st0 - fincstp - fldz ;default Figure.MCentrX - fld1 ;default Figure.MScale - mov dword[ecx+Figure.MCentrY],0 - @@: - fstp qword[ecx+Figure.MScale] - fistp dword[ecx+Figure.MCentrX] - - ;for Y coord - fild dword[mouse_prop_y] - fmulp st1,st0 - test bx,0x8000 - jnz .decr_y - ;увеличение масштаба - fild dword[ecx+Figure.MCentrY] ;add old value - fmul qword[zoom_plus] - faddp - jmp @f - .decr_y: - ;уменьшение масштаба - fchs - fild dword[ecx+Figure.MCentrY] ;add old value - fdiv qword[zoom_plus] - faddp - @@: - fistp dword[ecx+Figure.MCentrY] - - mov dword[offs_last_timer],0 - .end0: - - pop ecx ebx eax - ret - -;output: -; eax - buffer coord X (если курсор за буфером -1) -; ebx - buffer coord Y (если курсор за буфером -1) -align 4 -proc buf_get_mouse_coord - mcall SF_MOUSE_GET,SSF_WINDOW_POSITION - cmp ax,word[buf_0.t] - jl .no_buf ;не попали в окно буфера по оси y - mov ebx,eax - shr ebx,16 - cmp bx,word[buf_0.l] - jl .no_buf ;не попали в окно буфера по оси x - - and eax,0xffff ;оставляем координату y - sub ax,word[buf_0.t] - cmp eax,[buf_0.h] - jg .no_buf - sub bx,word[buf_0.l] - cmp ebx,[buf_0.w] - jg .no_buf - xchg eax,ebx - jmp .end_f - .no_buf: - xor eax,eax - not eax - xor ebx,ebx - not ebx - .end_f: - ret -endp - -align 4 -proc timer_funct uses eax ebx - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov [last_time],eax - - cmp dword[offs_last_timer],ObjData - je @f - mov dword[offs_last_timer],ObjData - stdcall draw_obj2d,ObjData - stdcall [buf2d_draw], buf_0 - @@: - ret -endp - -WINDOW_WIDTH = 775 -WINDOW_HEIGHT = 445 - -align 4 -draw_window: -pushad - mcall SF_REDRAW,SSF_BEGIN_DRAW - - ; *** рисование главного окна (выполняется 1 раз при запуске) *** - mov edx,[sc.work] - or edx,0x33000000 - mov edi,caption - mcall SF_CREATE_WINDOW,(20 shl 16)+WINDOW_WIDTH,(20 shl 16)+WINDOW_HEIGHT - - mov ecx,[ObjData.FigCount] - or ecx,ecx - jz .end0 - mov eax,[ObjData.FigData] - xor edx,edx - .cycle0: - stdcall FigCalculateSizes,[eax+4*edx],0 - inc edx - loop .cycle0 - stdcall ObjCalculateScale,ObjData - mov dword[offs_last_timer],0 - call timer_funct - .end0: - - stdcall [edit_box_draw], editFileName - stdcall [edit_box_draw], editCommand - - stdcall [option_box_draw], opt_grlist1 - push pb - call [progressbar_draw] - - ; *** создание кнопок на панель *** - mcall SF_DEFINE_BUTTON,(731 shl 16)+20,(75 shl 16)+20,3, [sc.work_button] - mcall , (15 shl 16)+20,(27 shl 16)+20,4 ;restore - mcall ,(538 shl 16)+20,,5 ;connect - mcall ,(563 shl 16)+20,,6 ;close connect - mcall ,(437 shl 16)+86,(378 shl 16)+20,7 ;cancel - mcall ,(616 shl 16)+136,(378 shl 16)+20,8 ;run - - ; *** - mov ecx,[sc.work_text] - or ecx,0x80000000 ;0x81000000 - textYcoord = 13;5 - mcall SF_DRAW_TEXT,(15 shl 16)+textYcoord,,txt_preview - mcall ,(424 shl 16)+textYcoord,,txt_port - mov ecx,[sc.work_button_text] - or ecx,0x81000000 - mcall ,(440 shl 16)+381,,txt_but_cancel - mcall ,(619 shl 16)+381,,txt_but_run - - ; *** рисование иконок на кнопках *** - mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16,(733 shl 16)+77 ;icon open - - add ebx,IMAGE_TOOLBAR_ICON_SIZE - mcall ,,,(17 shl 16)+29 ;restore scale - add ebx,IMAGE_TOOLBAR_ICON_SIZE - mcall ,,,(540 shl 16)+29 ;connect - add ebx,IMAGE_TOOLBAR_ICON_SIZE - mcall ,,,(565 shl 16)+29 ;close connect - ;;add ebx,IMAGE_TOOLBAR_ICON_SIZE - ;;mcall ,,,(439 shl 16)+380 ;cancel - add ebx,IMAGE_TOOLBAR_ICON_SIZE - mcall ,,,((638+97) shl 16)+380 ;run - - stdcall [buf2d_draw], buf_0 - - ;delete port button, if it exist - mov edx, 0x80000008 - mcall SF_DEFINE_BUTTON - ;draw button PORT - buttonPortX = 433 - buttonPortY = 27 ;50 - buttonPortTextXoffset = 5 - mov esi, 0x00AABBCC ;color button - mcall SF_DEFINE_BUTTON, buttonPortX*65536 + 95, buttonPortY*65536 + 20, 8 - ;draw text for button PORT - mov ebx, (buttonPortX+buttonPortTextXoffset) * 65536 + (buttonPortY+6) ;(x, y) - mov esi, 11 - mcall SF_DRAW_TEXT,, 0xFFFFFF, sz_PortMenu - ;stdcall [kmainmenu_draw], [main_menu] - ;mov word[coord.x], 0 - ;mov word[coord.y], 0 - ;stdcall [ksubmenu_draw], [port_menu], coord - - mcall SF_REDRAW,SSF_END_DRAW -popad - ret - -align 4 -key: - mcall SF_GET_KEY - - stdcall [edit_box_key], editFileName - stdcall [edit_box_key], editCommand - - mov ecx,eax - mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS - bt eax,2 ;left Ctrl - jc .key_Ctrl - bt eax,3 ;right Ctrl - jc .key_Ctrl - jmp .end0 - .key_Ctrl: - cmp ch,15 ;111 ;Ctrl+O - jne @f - call but_open_file - @@: - .end0: - jmp still - -align 4 -button: - mcall SF_GET_BUTTON - - cmp ah,3 - jne @f - call but_open_file - jmp still - @@: - cmp ah,4 - jne @f - call but_restore_zoom - jmp still - @@: - cmp ah, 8 - jne @f - push eax ebx ecx - mcall SF_THREAD_INFO, pi, -1 ;get window coord - - mov eax, dword[pi+34] - add eax, buttonPortX + 5 - mov word[coord.x], ax - - mov eax, dword[pi+38] - add eax, buttonPortY + 42 - mov word[coord.y], ax - - stdcall [ksubmenu_draw], [port_menu], coord - pop ecx ebx eax - @@: - ;cmp ah,5 - ;jne @f - ;call but_... - ;jmp still - ;@@: - cmp ah,1 - jne still -.exit: - stdcall [buf2d_delete],buf_0 - stdcall mem.Free,[image_data_toolbar] - stdcall mem.Free,[open_file_data] - mcall SF_TERMINATE_PROCESS - - - -align 4 -open_file_data dd 0 ;указатель на память для открытия файлов -open_file_size dd 0 ;размер открытого файла - -align 4 -but_open_file: - copy_path open_dialog_name,communication_area_default_path,file_name,0 - pushad - mov [OpenDialog_data.type],0 - stdcall [OpenDialog_Start],OpenDialog_data - cmp [OpenDialog_data.status],2 - je .end_open_file - ;код при удачном открытии диалога - jmp .end0 -.no_dlg: ;если минуем диалог открытия файла - pushad - mov esi,openfile_path - stdcall str_len,esi - add esi,eax - @@: ;цикл для поиска начала имени файла - dec esi - cmp byte[esi],'/' - je @f - cmp byte[esi],0x5c ;'\' - je @f - cmp esi,openfile_path - jg @b - @@: - inc esi - stdcall [OpenDialog_Set_file_name],OpenDialog_data,esi ;копируем имя файла в диалог сохранения - .end0: - push eax ebx ecx edx ;copy file name path from OpenDialog - mov eax, openfile_path - mov ebx, fileNameBuffer ;.data - mov ecx, 0 - @@: - mov dl, byte[eax] - cmp dl, 0 ;byte[eax], 0 - je @f - mov byte[ebx], dl - inc eax - inc ebx - inc ecx - jmp @b - @@: - mov byte[ebx], 0 - mov dword[fileNameBuffer.size], ecx - mov dword[editFileName.size], ecx - mov dword[editFileName.pos], ecx - pop edx ecx ebx eax - - mov [run_file_70.Function], SSF_GET_INFO - mov [run_file_70.Position], 0 - mov [run_file_70.Flags], 0 - mov dword[run_file_70.Count], 0 - mov dword[run_file_70.Buffer], open_b - mov byte[run_file_70+20], 0 - mov dword[run_file_70.FileName], openfile_path - mcall SF_FILE,run_file_70 - - mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах - inc ecx ;for text files - stdcall mem.ReAlloc,[open_file_data],ecx - mov [open_file_data],eax - dec ecx ;for text files - mov byte[eax+ecx],0 ;for text files - - mov [run_file_70.Function], SSF_READ_FILE - mov [run_file_70.Position], 0 - mov [run_file_70.Flags], 0 - mov dword[run_file_70.Count], ecx - m2m dword[run_file_70.Buffer], dword[open_file_data] - mov byte[run_file_70+20], 0 - mov dword[run_file_70.FileName], openfile_path - mcall SF_FILE,run_file_70 ;загружаем файл изображения - test eax,eax - jnz .end_open_file - cmp ebx,0xffffffff - je .end_open_file - mov [open_file_size],ebx - mcall SF_SET_CAPTION,1,openfile_path - - stdcall FileInit,[open_file_data],[open_file_size] - stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер - stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране - .end_open_file: - popad - ret - -;output: -; ecx - memory size for save file -align 4 -proc get_file_save_size uses eax ebx edx esi - mov ecx,100 ;title - mov ebx,ObjData - add ecx,50 ;object - mov edx,[ebx+Object.FigCount] - or edx,edx - jz .cycle1end - mov esi,[ebx+Object.FigData] -align 4 - .cycle1: ; цикл по фигурам - add ecx,80 ;figure - mov eax,[esi] - or eax,eax - jz @f - mov eax,[eax+Figure.PoiCount] - imul eax,70 - add ecx,eax ;points - @@: - add esi,4 - dec edx - jnz .cycle1 - .cycle1end: - ret -endp - -align 4 -proc but_restore_zoom - finit - fld1 - fstp qword[ObjData.MScale] - mov dword[ObjData.MCentrX],0 - mov dword[ObjData.MCentrY],0 - mov dword[offs_last_timer],0 - ret -endp - -;input: -; buf - указатель на строку, число должно быть в 10 или 16 ричном виде -;output: -; eax - число -align 4 -proc conv_str_to_int uses ebx ecx esi, buf:dword - xor eax,eax - xor ebx,ebx - mov esi,[buf] - - ;на случай если перед числом находятся пробелы - @@: - cmp byte[esi],' ' - jne @f - inc esi - jmp @b - @@: - - ;определение отрицательных чисел - xor ecx,ecx - inc ecx - cmp byte[esi],'-' - jne @f - dec ecx - inc esi - @@: - - cmp word[esi],'0x' - je .load_digit_16 - - .load_digit_10: ;считывание 10-тичных цифр - mov bl,byte[esi] - cmp bl,'0' - jl @f - cmp bl,'9' - jg @f - sub bl,'0' - imul eax,10 - add eax,ebx - inc esi - jmp .load_digit_10 - jmp @f - - .load_digit_16: ;считывание 16-ричных цифр - add esi,2 - .cycle_16: - mov bl,byte[esi] - cmp bl,'0' - jl @f - cmp bl,'f' - jg @f - cmp bl,'9' - jle .us1 - cmp bl,'A' - jl @f ;отсеиваем символы >'9' и <'A' - .us1: ;составное условие - cmp bl,'F' - jle .us2 - cmp bl,'a' - jl @f ;отсеиваем символы >'F' и <'a' - sub bl,32 ;переводим символы в верхний регистр, для упрощения их последущей обработки - .us2: ;составное условие - sub bl,'0' - cmp bl,9 - jle .cor1 - sub bl,7 ;convert 'A' to '10' - .cor1: - shl eax,4 - add eax,ebx - inc esi - jmp .cycle_16 - @@: - or ecx,ecx ;если число отрицательное - jnz @f - sub ecx,eax - mov eax,ecx - @@: - ret -endp - - -;данные для диалога открытия файлов -align 4 -OpenDialog_data: -.type dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию -.procinfo dd procinfo ;+4 -.com_area_name dd communication_area_name ;+8 -.com_area dd 0 ;+12 -.opendir_path dd plugin_path ;+16 -.dir_default_path dd default_dir ;+20 -.start_path dd file_name ;+24 путь к диалогу открытия файлов -.draw_window dd draw_window ;+28 -.status dd 0 ;+32 -.openfile_path dd openfile_path ;+36 путь к открываемому файлу -.filename_area dd filename_area ;+40 -.filter_area dd Filter -.x: -.x_size dw 420 ;+48 ; Window X size -.x_start dw 10 ;+50 ; Window X position -.y: -.y_size dw 320 ;+52 ; Window y size -.y_start dw 10 ;+54 ; Window Y position - -default_dir db '/sys',0 - -communication_area_name: - db 'FFFFFFFF_open_dialog',0 -open_dialog_name: - db 'opendial',0 -communication_area_default_path: - db '/sys/File managers/',0 - -Filter: -dd Filter.end - Filter ;.1 -.1: -db 'NC',0 -db 'PNG',0 -.end: -db 0 - - -;[ -;for test -main_menu dd 0 -port_menu dd 0 - -sz_PortMenu db 'COM 12 ',0 -sz_COMport db 'COM port 12',0 -sz_USBport db 'USB port ',0 -sz_OTHERport db 'Other port ',0 - -coord: - .x dw 100 - .y dw 200 -;] - -align 4 -system_dir_0 db '/sys/lib/' -lib_name_0 db 'proc_lib.obj',0 -system_dir_1 db '/sys/lib/' -lib_name_1 db 'libimg.obj',0 -system_dir_2 db '/sys/lib/' -lib_name_2 db 'buf2d.obj',0 -system_dir_3 db '/sys/lib/' -lib_name_3 db 'box_lib.obj',0 -system_dir_4 db '/sys/lib/' -lib_name_4 db 'kmenu.obj',0 - -align 4 -l_libs_start: - lib_0 l_libs lib_name_0, file_name, system_dir_0, import_proclib - lib_1 l_libs lib_name_1, file_name, system_dir_1, import_libimg - lib_2 l_libs lib_name_2, file_name, system_dir_2, import_buf2d - lib_3 l_libs lib_name_3, file_name, system_dir_3, import_box_lib - lib_4 l_libs lib_name_4, file_name, system_dir_4, import_libkmenu -l_libs_end: - -align 4 -import_libimg: - dd alib_init1 - img_is_img dd aimg_is_img - img_info dd aimg_info - img_from_file dd aimg_from_file - img_to_file dd aimg_to_file - img_from_rgb dd aimg_from_rgb - img_to_rgb dd aimg_to_rgb - img_to_rgb2 dd aimg_to_rgb2 - img_decode dd aimg_decode - img_encode dd aimg_encode - img_create dd aimg_create - img_destroy dd aimg_destroy - img_destroy_layer dd aimg_destroy_layer - img_count dd aimg_count - img_lock_bits dd aimg_lock_bits - img_unlock_bits dd aimg_unlock_bits - img_flip dd aimg_flip - img_flip_layer dd aimg_flip_layer - img_rotate dd aimg_rotate - img_rotate_layer dd aimg_rotate_layer - img_draw dd aimg_draw - - dd 0,0 - alib_init1 db 'lib_init',0 - aimg_is_img db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение - aimg_info db 'img_info',0 - aimg_from_file db 'img_from_file',0 - aimg_to_file db 'img_to_file',0 - aimg_from_rgb db 'img_from_rgb',0 - aimg_to_rgb db 'img_to_rgb',0 ;преобразование изображения в данные RGB - aimg_to_rgb2 db 'img_to_rgb2',0 - aimg_decode db 'img_decode',0 ;автоматически определяет формат графических данных - aimg_encode db 'img_encode',0 - aimg_create db 'img_create',0 - aimg_destroy db 'img_destroy',0 - aimg_destroy_layer db 'img_destroy_layer',0 - aimg_count db 'img_count',0 - aimg_lock_bits db 'img_lock_bits',0 - aimg_unlock_bits db 'img_unlock_bits',0 - aimg_flip db 'img_flip',0 - aimg_flip_layer db 'img_flip_layer',0 - aimg_rotate db 'img_rotate',0 - aimg_rotate_layer db 'img_rotate_layer',0 - aimg_draw db 'img_draw',0 - -align 4 -import_proclib: - OpenDialog_Init dd aOpenDialog_Init - OpenDialog_Start dd aOpenDialog_Start - OpenDialog_Set_file_name dd aOpenDialog_Set_file_name - ;OpenDialog_Set_file_ext dd aOpenDialog_Set_file_ext -dd 0,0 - aOpenDialog_Init db 'OpenDialog_init',0 - aOpenDialog_Start db 'OpenDialog_start',0 - aOpenDialog_Set_file_name db 'OpenDialog_set_file_name',0 - ;aOpenDialog_Set_file_ext db 'OpenDialog_set_file_ext',0 - -align 4 -import_buf2d: - init dd sz_init - buf2d_create dd sz_buf2d_create - buf2d_create_f_img dd sz_buf2d_create_f_img - buf2d_clear dd sz_buf2d_clear - buf2d_draw dd sz_buf2d_draw - buf2d_delete dd sz_buf2d_delete - buf2d_resize dd sz_buf2d_resize - buf2d_line dd sz_buf2d_line - buf2d_line_sm dd sz_buf2d_line_sm - buf2d_rect_by_size dd sz_buf2d_rect_by_size - buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size - buf2d_circle dd sz_buf2d_circle - buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2 - buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2 - buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8 - buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32 - buf2d_bit_blt dd sz_buf2d_bit_blt - buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp - buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha - buf2d_curve_bezier dd sz_buf2d_curve_bezier - buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix - buf2d_draw_text dd sz_buf2d_draw_text - buf2d_crop_color dd sz_buf2d_crop_color - buf2d_flip_h dd sz_buf2d_flip_h - buf2d_flip_v dd sz_buf2d_flip_v - buf2d_offset_h dd sz_buf2d_offset_h - buf2d_flood_fill dd sz_buf2d_flood_fill - buf2d_set_pixel dd sz_buf2d_set_pixel - dd 0,0 - sz_init db 'lib_init',0 - sz_buf2d_create db 'buf2d_create',0 - sz_buf2d_create_f_img db 'buf2d_create_f_img',0 - sz_buf2d_clear db 'buf2d_clear',0 - sz_buf2d_draw db 'buf2d_draw',0 - sz_buf2d_delete db 'buf2d_delete',0 - sz_buf2d_resize db 'buf2d_resize',0 - sz_buf2d_line db 'buf2d_line',0 - sz_buf2d_line_sm db 'buf2d_line_sm',0 - sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0 - sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0 - sz_buf2d_circle db 'buf2d_circle',0 - sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0 - sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0 - sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0 - sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0 - sz_buf2d_bit_blt db 'buf2d_bit_blt',0 - sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0 - sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0 - sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0 - sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0 - sz_buf2d_draw_text db 'buf2d_draw_text',0 - sz_buf2d_crop_color db 'buf2d_crop_color',0 - sz_buf2d_flip_h db 'buf2d_flip_h',0 - sz_buf2d_flip_v db 'buf2d_flip_v',0 - sz_buf2d_offset_h db 'buf2d_offset_h',0 - sz_buf2d_flood_fill db 'buf2d_flood_fill',0 - sz_buf2d_set_pixel db 'buf2d_set_pixel',0 - -align 4 -import_box_lib: - dd sz_init1 - - init_checkbox dd sz_Init_checkbox - check_box_draw dd sz_Check_box_draw - check_box_mouse dd sz_Check_box_mouse - ;version_ch dd sz_Version_ch - - option_box_draw dd sz_Option_box_draw - option_box_mouse dd sz_Option_box_mouse - ;version_op dd sz_Version_op - - edit_box_draw dd sz_edit_box_draw - edit_box_key dd sz_edit_box_key - edit_box_mouse dd sz_edit_box_mouse - edit_box_set_text dd sz_edit_box_set_text - scrollbar_ver_draw dd sz_scrollbar_ver_draw - scrollbar_hor_draw dd sz_scrollbar_hor_draw - - progressbar_draw dd sz_progressbar_draw - progressbar_progress dd sz_progressbar_progress - - dd 0,0 - sz_init1 db 'lib_init',0 - - sz_Init_checkbox db 'init_checkbox2',0 - sz_Check_box_draw db 'check_box_draw2',0 - sz_Check_box_mouse db 'check_box_mouse2',0 - ;sz_Version_ch db 'version_ch2',0 - - sz_Option_box_draw db 'option_box_draw',0 - sz_Option_box_mouse db 'option_box_mouse',0 - ;sz_Version_op db 'version_op',0 - - sz_edit_box_draw db 'edit_box_draw',0 - sz_edit_box_key db 'edit_box_key',0 - sz_edit_box_mouse db 'edit_box_mouse',0 - sz_edit_box_set_text db 'edit_box_set_text',0 - sz_scrollbar_ver_draw db 'scrollbar_v_draw',0 - sz_scrollbar_hor_draw db 'scrollbar_h_draw',0 - - sz_progressbar_draw db 'progressbar_draw', 0 - sz_progressbar_progress db 'progressbar_progress', 0 - -align 4 -import_libkmenu: - kmenu_init dd akmenu_init - kmainmenu_draw dd akmainmenu_draw - kmainmenu_dispatch_cursorevent dd akmainmenu_dispatch_cursorevent - ksubmenu_new dd aksubmenu_new - ksubmenu_delete dd aksubmenu_delete - ksubmenu_draw dd aksubmenu_draw - ksubmenu_add dd aksubmenu_add - kmenuitem_new dd akmenuitem_new - kmenuitem_delete dd akmenuitem_delete - kmenuitem_draw dd akmenuitem_draw -dd 0,0 - akmenu_init db 'kmenu_init',0 - akmainmenu_draw db 'kmainmenu_draw',0 - akmainmenu_dispatch_cursorevent db 'kmainmenu_dispatch_cursorevent',0 - aksubmenu_new db 'ksubmenu_new',0 - aksubmenu_delete db 'ksubmenu_delete',0 - aksubmenu_draw db 'ksubmenu_draw',0 - aksubmenu_add db 'ksubmenu_add',0 - akmenuitem_new db 'kmenuitem_new',0 - akmenuitem_delete db 'kmenuitem_delete',0 - akmenuitem_draw db 'kmenuitem_draw',0 - -button_press dd 0 ;for kmenu - -align 4 -mouse_dd dd 0 -last_time dd 0 - -align 16 -sc system_colors - -align 16 -procinfo process_information - -align 4 -buf_0: dd 0 ;указатель на буфер изображения -.l: dw 15 ;+4 left -.t: dw 50 ;+6 top -.w: dd 384 ;+8 w -.h: dd 350 ;+12 h -.color: dd 0xffffd0 ;+16 color - db 24 ;+20 bit in pixel - -align 4 -buf_1: - dd 0 ;указатель на буфер изображения - dd 0 ;+4 left,top -.w: dd 0 -.h: dd 0,0,24 ;+12 color,bit in pixel - -font_h dd 0 ;высота шрифта - -;input: -; eax - число -; edi - буфер для строки -; len - длинна буфера -;output: -align 4 -proc convert_int_to_str uses eax ecx edx edi esi, len:dword - mov esi,[len] - add esi,edi - dec esi - call .str - ret -endp - -align 4 -.str: - mov ecx,10 - cmp eax,ecx - jb @f - xor edx,edx - div ecx - push edx - ;dec edi ;смещение необходимое для записи с конца строки - call .str - pop eax - @@: - cmp edi,esi - jge @f - or al,0x30 - stosb - mov byte[edi],0 ;в конец строки ставим 0, что-бы не вылазил мусор - @@: - ret - -align 4 -proc mem_copy uses ecx esi edi, destination:dword, source:dword, len:dword - cld - mov esi, [source] - mov edi, [destination] - mov ecx, [len] - rep movsb - ret -endp - -edMaxSize = 511 -edMax = 0 ;max, size, pos - -align 4 -editFileName edit_box 270,450,78, 0xffffff, 0x6a9480, 0, 0xAABBCC, 0, edMaxSize, fileNameBuffer.data, mouse_dd, 0, edMax, edMax -editCommand edit_box 150,450,121, 0xffffff, 0x6a9480, 0, 0xAABBCC, 0, edMaxSize, commandBuffer.data, mouse_dd, 0, edMax, edMax - -opt1 option_box opt_gr1, 433,64, 6,12,0xd0d0ff, 0xff, 0x80ff,txt_filename,txt_filename.end-txt_filename -opt2 option_box opt_gr1, 433,107,6,12,0xd0d0ff, 0xff, 0x80ff,txt_command,txt_command.end-txt_command -opt_gr1 dd opt1 -align 4 -opt_grlist1 dd opt1,opt2,0 ;end option group - -pb: -.value dd 0 -.left dd 0 -.top dd 0 -.width dd 0 -.height dd 0 -.style dd 0 -.min dd 0 -.max dd 0 -.back_color dd 0 -.progress_color dd 0 -.frame_color dd 0 - -fileNameBuffer: -.data: rb 512 -.size: rd 1 -fileNameBufferEnd: - -commandBuffer: -.data: rb 512 -.size: rd 1 -commandBufferEnd: - -align 16 -i_end: - rb 2048 -thread_coords: - rb 2048 -thread_scale: - rb 2048 -thread_n_file: - rb 2048 -stacktop: - sys_path rb 1024 - file_name rb 2048 - plugin_path rb 4096 - openfile_path rb 4096 - filename_area rb 256 - pi rb 1024 -mem: - +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + +;CNC CONTROL +;Igor Afanasyev (aka IgorA) and Sergey Efremenkov (aka theonlymirage), 2020 + +;02.10.18 - Only prototype UI +;08.10.18 - Add ComboBox (Button + KMenu), small text + +format binary as "" +use32 + org 0 + db 'MENUET01' + dd 1,start,i_end,mem,stacktop,file_name,sys_path + +include '../../macros.inc' +include '../../proc32.inc' +include '../../KOSfuncs.inc' +include '../../load_img.inc' +include '../../load_lib.mac' +include '../../develop/libraries/libs-dev/libimg/libimg.inc' +include '../../develop/libraries/box_lib/trunk/box_lib.mac' +include 'lang.inc' +include 'cnc_control.inc' +include '../../develop/info3ds/info_fun_float.inc' + +KMENUITEM_NORMAL equ 0 +KMENUITEM_SUBMENU equ 1 +KMENUITEM_SEPARATOR equ 2 + +@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load +caption db 'CNC Control 18.12.20',0 ;подпись окна + +run_file_70 FileInfoBlock + +offs_last_timer dd 0 ;последний сдвиг показаный в функции таймера + +IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3 +image_data_toolbar dd 0 ;указатель на временную память. для нужен преобразования изображения +icon_tl_sys dd 0 ;указатель на память для хранения системных иконок +icon_toolbar dd 0 ;указатель на память для хранения иконок объектов + +align 4 +start: + ;--- copy cmd line --- + mov esi,file_name + mov edi,openfile_path +@@: + lodsd + or eax,eax + jz @f ;выход, если 0 + stosd + jmp @b +@@: + stosd + + load_libraries l_libs_start,l_libs_end + ;проверка на сколько удачно загузилась библиотека + mov ebp,lib_0 + cmp dword [ebp+ll_struc_size-4],0 + jz @f + mcall SF_TERMINATE_PROCESS + @@: + mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors + mcall SF_SET_EVENTS_MASK,0xC0000027 + stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога + + stdcall [buf2d_create], buf_0 ;создание буфера + + ;шрифт делаем до создания панели (для экономии указателя image_data_toolbar) + include_image_file '..\..\fs\kfar\font6x9.bmp', image_data_toolbar, buf_1.w,buf_1.h + stdcall [buf2d_create_f_img], buf_1,[image_data_toolbar] ;создаем буфер + stdcall mem.Free,[image_data_toolbar] ;освобождаем память + stdcall [buf2d_conv_24_to_8], buf_1,1 ;делаем буфер прозрачности 8 бит + stdcall [buf2d_convert_text_matrix], buf_1 + mov eax,[buf_1.h] + shr eax,8 + mov [font_h],eax + + include_image_file 'toolbar.png', image_data_toolbar + + ;*** установка времени для таймера + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov [last_time],eax + + ;call but_new_file + option_boxes_set_sys_color sc,opt_grlist1 + + ;progress bar + mov [pb.left], dword 50 + mov [pb.top], dword 30 + mov [pb.width], dword 350 + mov [pb.height], dword 17 + mov [pb.max], dword 100;599 + mov [pb.min], dword 0 ;-397 + mov [pb.value], dword 0 ;-397 + mov [pb.back_color], dword 00C8D0D4h + mov [pb.progress_color], dword 8072B7EBh + mov [pb.frame_color], dword 00406175h + + ;port menu + stdcall [kmenu_init], sc ;kmenu initialisation + ;stdcall [ksubmenu_new] + ;mov [main_menu], eax + + stdcall [ksubmenu_new] + mov [port_menu], eax + stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_COMport, 110 + stdcall [ksubmenu_add], [port_menu], eax + stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_USBport, 111 + stdcall [ksubmenu_add], [port_menu], eax + ;stdcall [kmenuitem_new], KMENUITEM_SEPARATOR, 0, 0 + ;stdcall [ksubmenu_add], [port_menu], eax + ;stdcall [kmenuitem_new], KMENUITEM_NORMAL, sz_OTHERport, 112 + ;stdcall [ksubmenu_add], [port_menu], eax + stdcall [kmenuitem_new], KMENUITEM_SUBMENU, sz_PortMenu, [port_menu] + ;stdcall [ksubmenu_add], [main_menu], eax + + ;open file from cmd line + cmp dword[openfile_path],0 + je @f + call but_open_file.no_dlg + @@: + +align 4 +red_win: + call draw_window + +align 4 +still: + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov ebx,[last_time] + add ebx,10 ;задержка + cmp ebx,eax + jge @f + mov ebx,eax + @@: + sub ebx,eax + mcall SF_WAIT_EVENT_TIMEOUT + cmp eax,0 + jne @f + call timer_funct + jmp still + @@: + + cmp al,1 + jz red_win + cmp al,2 + jz key + cmp al,3 + jz button + cmp al,6 + jne @f + mcall SF_THREAD_INFO,procinfo,-1 + cmp ax,word[procinfo.window_stack_position] + jne @f ;окно не активно + call mouse + @@: + jmp still + +align 4 +mouse: + stdcall [option_box_mouse], opt_grlist1 + stdcall [edit_box_mouse], editFileName + stdcall [edit_box_mouse], editCommand + stdcall [kmainmenu_dispatch_cursorevent], [port_menu] ;[main_menu] + + push eax ebx ecx + mcall SF_MOUSE_GET,SSF_BUTTON_EXT + bt eax,8 + jnc @f + ;mouse l. but. press + call mouse_left_d + jmp .end_l + @@: + bt eax,16 + jnc .end_l + ;mouse l. but. up + call mouse_left_u + ;jmp .end_l + .end_l: + + + call buf_get_mouse_coord + cmp eax,-1 + je .end0 + shl eax,1 + sub eax,[buf_0.w] + sar eax,1 + mov [mouse_prop_x],eax + mov ecx,ObjData + shl ebx,1 + sub ebx,[buf_0.h] + sar ebx,1 + mov [mouse_prop_y],ebx + + mcall SF_MOUSE_GET,SSF_SCROLL_DATA + test ax,ax + jz .end0 + finit + fld qword[zoom_plus] + fld1 + fsubp + fld st0 ;for Y coord + + ;for X coord + fild dword[mouse_prop_x] + fmulp st1,st0 + + mov ebx,eax + test ax,0x8000 + jnz .decr + ;увеличение масштаба + fchs + fild dword[ecx+Figure.MCentrX] ;add old value + fmul qword[zoom_plus] + faddp + + fld qword[ecx+Figure.MScale] + fmul qword[zoom_plus] + ;if (Figure.MScale>16.0) + ;... + jmp @f + .decr: + ;уменьшение масштаба + fild dword[ecx+Figure.MCentrX] ;add old value + fdiv qword[zoom_plus] + faddp + + fld qword[ecx+Figure.MScale] + fdiv qword[zoom_plus] + fld1 + fcomp + fstsw ax + sahf + jbe @f + ;if (Figure.MScale<1.0) + ffree st0 + fincstp + ffree st0 + fincstp + fldz ;default Figure.MCentrX + fld1 ;default Figure.MScale + mov dword[ecx+Figure.MCentrY],0 + @@: + fstp qword[ecx+Figure.MScale] + fistp dword[ecx+Figure.MCentrX] + + ;for Y coord + fild dword[mouse_prop_y] + fmulp st1,st0 + test bx,0x8000 + jnz .decr_y + ;увеличение масштаба + fild dword[ecx+Figure.MCentrY] ;add old value + fmul qword[zoom_plus] + faddp + jmp @f + .decr_y: + ;уменьшение масштаба + fchs + fild dword[ecx+Figure.MCentrY] ;add old value + fdiv qword[zoom_plus] + faddp + @@: + fistp dword[ecx+Figure.MCentrY] + + mov dword[offs_last_timer],0 + .end0: + + pop ecx ebx eax + ret + +;output: +; eax - buffer coord X (если курсор за буфером -1) +; ebx - buffer coord Y (если курсор за буфером -1) +align 4 +proc buf_get_mouse_coord + mcall SF_MOUSE_GET,SSF_WINDOW_POSITION + cmp ax,word[buf_0.t] + jl .no_buf ;не попали в окно буфера по оси y + mov ebx,eax + shr ebx,16 + cmp bx,word[buf_0.l] + jl .no_buf ;не попали в окно буфера по оси x + + and eax,0xffff ;оставляем координату y + sub ax,word[buf_0.t] + cmp eax,[buf_0.h] + jg .no_buf + sub bx,word[buf_0.l] + cmp ebx,[buf_0.w] + jg .no_buf + xchg eax,ebx + jmp .end_f + .no_buf: + xor eax,eax + not eax + xor ebx,ebx + not ebx + .end_f: + ret +endp + +align 4 +proc timer_funct uses eax ebx + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov [last_time],eax + + cmp dword[offs_last_timer],ObjData + je @f + mov dword[offs_last_timer],ObjData + stdcall draw_obj2d,ObjData + stdcall [buf2d_draw], buf_0 + @@: + ret +endp + +WINDOW_WIDTH = 775 +WINDOW_HEIGHT = 445 + +align 4 +draw_window: +pushad + mcall SF_REDRAW,SSF_BEGIN_DRAW + + ; *** рисование главного окна (выполняется 1 раз при запуске) *** + mov edx,[sc.work] + or edx,0x33000000 + mov edi,caption + mcall SF_CREATE_WINDOW,(20 shl 16)+WINDOW_WIDTH,(20 shl 16)+WINDOW_HEIGHT + + mov ecx,[ObjData.FigCount] + or ecx,ecx + jz .end0 + mov eax,[ObjData.FigData] + xor edx,edx + .cycle0: + stdcall FigCalculateSizes,[eax+4*edx],0 + inc edx + loop .cycle0 + stdcall ObjCalculateScale,ObjData + mov dword[offs_last_timer],0 + call timer_funct + .end0: + + stdcall [edit_box_draw], editFileName + stdcall [edit_box_draw], editCommand + + stdcall [option_box_draw], opt_grlist1 + push pb + call [progressbar_draw] + + ; *** создание кнопок на панель *** + mcall SF_DEFINE_BUTTON,(731 shl 16)+20,(75 shl 16)+20,3, [sc.work_button] + mcall , (15 shl 16)+20,(27 shl 16)+20,4 ;restore + mcall ,(538 shl 16)+20,,5 ;connect + mcall ,(563 shl 16)+20,,6 ;close connect + mcall ,(437 shl 16)+86,(378 shl 16)+20,7 ;cancel + mcall ,(616 shl 16)+136,(378 shl 16)+20,8 ;run + + ; *** + mov ecx,[sc.work_text] + or ecx,0x80000000 ;0x81000000 + textYcoord = 13;5 + mcall SF_DRAW_TEXT,(15 shl 16)+textYcoord,,txt_preview + mcall ,(424 shl 16)+textYcoord,,txt_port + mov ecx,[sc.work_button_text] + or ecx,0x81000000 + mcall ,(440 shl 16)+381,,txt_but_cancel + mcall ,(619 shl 16)+381,,txt_but_run + + ; *** рисование иконок на кнопках *** + mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16,(733 shl 16)+77 ;icon open + + add ebx,IMAGE_TOOLBAR_ICON_SIZE + mcall ,,,(17 shl 16)+29 ;restore scale + add ebx,IMAGE_TOOLBAR_ICON_SIZE + mcall ,,,(540 shl 16)+29 ;connect + add ebx,IMAGE_TOOLBAR_ICON_SIZE + mcall ,,,(565 shl 16)+29 ;close connect + ;;add ebx,IMAGE_TOOLBAR_ICON_SIZE + ;;mcall ,,,(439 shl 16)+380 ;cancel + add ebx,IMAGE_TOOLBAR_ICON_SIZE + mcall ,,,((638+97) shl 16)+380 ;run + + stdcall [buf2d_draw], buf_0 + + ;delete port button, if it exist + mov edx, 0x80000008 + mcall SF_DEFINE_BUTTON + ;draw button PORT + buttonPortX = 433 + buttonPortY = 27 ;50 + buttonPortTextXoffset = 5 + mov esi, 0x00AABBCC ;color button + mcall SF_DEFINE_BUTTON, buttonPortX*65536 + 95, buttonPortY*65536 + 20, 8 + ;draw text for button PORT + mov ebx, (buttonPortX+buttonPortTextXoffset) * 65536 + (buttonPortY+6) ;(x, y) + mov esi, 11 + mcall SF_DRAW_TEXT,, 0xFFFFFF, sz_PortMenu + ;stdcall [kmainmenu_draw], [main_menu] + ;mov word[coord.x], 0 + ;mov word[coord.y], 0 + ;stdcall [ksubmenu_draw], [port_menu], coord + + mcall SF_REDRAW,SSF_END_DRAW +popad + ret + +align 4 +key: + mcall SF_GET_KEY + + stdcall [edit_box_key], editFileName + stdcall [edit_box_key], editCommand + + mov ecx,eax + mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS + bt eax,2 ;left Ctrl + jc .key_Ctrl + bt eax,3 ;right Ctrl + jc .key_Ctrl + jmp .end0 + .key_Ctrl: + cmp ch,15 ;111 ;Ctrl+O + jne @f + call but_open_file + @@: + .end0: + jmp still + +align 4 +button: + mcall SF_GET_BUTTON + + cmp ah,3 + jne @f + call but_open_file + jmp still + @@: + cmp ah,4 + jne @f + call but_restore_zoom + jmp still + @@: + cmp ah, 8 + jne @f + push eax ebx ecx + mcall SF_THREAD_INFO, pi, -1 ;get window coord + + mov eax, dword[pi+34] + add eax, buttonPortX + 5 + mov word[coord.x], ax + + mov eax, dword[pi+38] + add eax, buttonPortY + 42 + mov word[coord.y], ax + + stdcall [ksubmenu_draw], [port_menu], coord + pop ecx ebx eax + @@: + ;cmp ah,5 + ;jne @f + ;call but_... + ;jmp still + ;@@: + cmp ah,1 + jne still +.exit: + stdcall [buf2d_delete],buf_0 + stdcall mem.Free,[image_data_toolbar] + stdcall mem.Free,[open_file_data] + mcall SF_TERMINATE_PROCESS + + + +align 4 +open_file_data dd 0 ;указатель на память для открытия файлов +open_file_size dd 0 ;размер открытого файла + +align 4 +but_open_file: + copy_path open_dialog_name,communication_area_default_path,file_name,0 + pushad + mov [OpenDialog_data.type],0 + stdcall [OpenDialog_Start],OpenDialog_data + cmp [OpenDialog_data.status],2 + je .end_open_file + ;код при удачном открытии диалога + jmp .end0 +.no_dlg: ;если минуем диалог открытия файла + pushad + mov esi,openfile_path + stdcall str_len,esi + add esi,eax + @@: ;цикл для поиска начала имени файла + dec esi + cmp byte[esi],'/' + je @f + cmp byte[esi],0x5c ;'\' + je @f + cmp esi,openfile_path + jg @b + @@: + inc esi + stdcall [OpenDialog_Set_file_name],OpenDialog_data,esi ;копируем имя файла в диалог сохранения + .end0: + push eax ebx ecx edx ;copy file name path from OpenDialog + mov eax, openfile_path + mov ebx, fileNameBuffer ;.data + mov ecx, 0 + @@: + mov dl, byte[eax] + cmp dl, 0 ;byte[eax], 0 + je @f + mov byte[ebx], dl + inc eax + inc ebx + inc ecx + jmp @b + @@: + mov byte[ebx], 0 + mov dword[fileNameBuffer.size], ecx + mov dword[editFileName.size], ecx + mov dword[editFileName.pos], ecx + pop edx ecx ebx eax + + mov [run_file_70.Function], SSF_GET_INFO + mov [run_file_70.Position], 0 + mov [run_file_70.Flags], 0 + mov dword[run_file_70.Count], 0 + mov dword[run_file_70.Buffer], open_b + mov byte[run_file_70+20], 0 + mov dword[run_file_70.FileName], openfile_path + mcall SF_FILE,run_file_70 + + mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах + inc ecx ;for text files + stdcall mem.ReAlloc,[open_file_data],ecx + mov [open_file_data],eax + dec ecx ;for text files + mov byte[eax+ecx],0 ;for text files + + mov [run_file_70.Function], SSF_READ_FILE + mov [run_file_70.Position], 0 + mov [run_file_70.Flags], 0 + mov dword[run_file_70.Count], ecx + m2m dword[run_file_70.Buffer], dword[open_file_data] + mov byte[run_file_70+20], 0 + mov dword[run_file_70.FileName], openfile_path + mcall SF_FILE,run_file_70 ;загружаем файл изображения + test eax,eax + jnz .end_open_file + cmp ebx,0xffffffff + je .end_open_file + mov [open_file_size],ebx + mcall SF_SET_CAPTION,1,openfile_path + + stdcall FileInit,[open_file_data],[open_file_size] + stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер + stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране + .end_open_file: + popad + ret + +;output: +; ecx - memory size for save file +align 4 +proc get_file_save_size uses eax ebx edx esi + mov ecx,100 ;title + mov ebx,ObjData + add ecx,50 ;object + mov edx,[ebx+Object.FigCount] + or edx,edx + jz .cycle1end + mov esi,[ebx+Object.FigData] +align 4 + .cycle1: ; цикл по фигурам + add ecx,80 ;figure + mov eax,[esi] + or eax,eax + jz @f + mov eax,[eax+Figure.PoiCount] + imul eax,70 + add ecx,eax ;points + @@: + add esi,4 + dec edx + jnz .cycle1 + .cycle1end: + ret +endp + +align 4 +proc but_restore_zoom + finit + fld1 + fstp qword[ObjData.MScale] + mov dword[ObjData.MCentrX],0 + mov dword[ObjData.MCentrY],0 + mov dword[offs_last_timer],0 + ret +endp + +;input: +; buf - указатель на строку, число должно быть в 10 или 16 ричном виде +;output: +; eax - число +align 4 +proc conv_str_to_int uses ebx ecx esi, buf:dword + xor eax,eax + xor ebx,ebx + mov esi,[buf] + + ;на случай если перед числом находятся пробелы + @@: + cmp byte[esi],' ' + jne @f + inc esi + jmp @b + @@: + + ;определение отрицательных чисел + xor ecx,ecx + inc ecx + cmp byte[esi],'-' + jne @f + dec ecx + inc esi + @@: + + cmp word[esi],'0x' + je .load_digit_16 + + .load_digit_10: ;считывание 10-тичных цифр + mov bl,byte[esi] + cmp bl,'0' + jl @f + cmp bl,'9' + jg @f + sub bl,'0' + imul eax,10 + add eax,ebx + inc esi + jmp .load_digit_10 + jmp @f + + .load_digit_16: ;считывание 16-ричных цифр + add esi,2 + .cycle_16: + mov bl,byte[esi] + cmp bl,'0' + jl @f + cmp bl,'f' + jg @f + cmp bl,'9' + jle .us1 + cmp bl,'A' + jl @f ;отсеиваем символы >'9' и <'A' + .us1: ;составное условие + cmp bl,'F' + jle .us2 + cmp bl,'a' + jl @f ;отсеиваем символы >'F' и <'a' + sub bl,32 ;переводим символы в верхний регистр, для упрощения их последущей обработки + .us2: ;составное условие + sub bl,'0' + cmp bl,9 + jle .cor1 + sub bl,7 ;convert 'A' to '10' + .cor1: + shl eax,4 + add eax,ebx + inc esi + jmp .cycle_16 + @@: + or ecx,ecx ;если число отрицательное + jnz @f + sub ecx,eax + mov eax,ecx + @@: + ret +endp + + +;данные для диалога открытия файлов +align 4 +OpenDialog_data: +.type dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию +.procinfo dd procinfo ;+4 +.com_area_name dd communication_area_name ;+8 +.com_area dd 0 ;+12 +.opendir_path dd plugin_path ;+16 +.dir_default_path dd default_dir ;+20 +.start_path dd file_name ;+24 путь к диалогу открытия файлов +.draw_window dd draw_window ;+28 +.status dd 0 ;+32 +.openfile_path dd openfile_path ;+36 путь к открываемому файлу +.filename_area dd filename_area ;+40 +.filter_area dd Filter +.x: +.x_size dw 420 ;+48 ; Window X size +.x_start dw 10 ;+50 ; Window X position +.y: +.y_size dw 320 ;+52 ; Window y size +.y_start dw 10 ;+54 ; Window Y position + +default_dir db '/sys',0 + +communication_area_name: + db 'FFFFFFFF_open_dialog',0 +open_dialog_name: + db 'opendial',0 +communication_area_default_path: + db '/sys/File managers/',0 + +Filter: +dd Filter.end - Filter ;.1 +.1: +db 'NC',0 +db 'PNG',0 +.end: +db 0 + + +;[ +;for test +main_menu dd 0 +port_menu dd 0 + +sz_PortMenu db 'COM 12 ',0 +sz_COMport db 'COM port 12',0 +sz_USBport db 'USB port ',0 +sz_OTHERport db 'Other port ',0 + +coord: + .x dw 100 + .y dw 200 +;] + +align 4 +system_dir_0 db '/sys/lib/' +lib_name_0 db 'proc_lib.obj',0 +system_dir_1 db '/sys/lib/' +lib_name_1 db 'libimg.obj',0 +system_dir_2 db '/sys/lib/' +lib_name_2 db 'buf2d.obj',0 +system_dir_3 db '/sys/lib/' +lib_name_3 db 'box_lib.obj',0 +system_dir_4 db '/sys/lib/' +lib_name_4 db 'kmenu.obj',0 + +align 4 +l_libs_start: + lib_0 l_libs lib_name_0, file_name, system_dir_0, import_proclib + lib_1 l_libs lib_name_1, file_name, system_dir_1, import_libimg + lib_2 l_libs lib_name_2, file_name, system_dir_2, import_buf2d + lib_3 l_libs lib_name_3, file_name, system_dir_3, import_box_lib + lib_4 l_libs lib_name_4, file_name, system_dir_4, import_libkmenu +l_libs_end: + +align 4 +import_libimg: + dd alib_init1 + img_is_img dd aimg_is_img + img_info dd aimg_info + img_from_file dd aimg_from_file + img_to_file dd aimg_to_file + img_from_rgb dd aimg_from_rgb + img_to_rgb dd aimg_to_rgb + img_to_rgb2 dd aimg_to_rgb2 + img_decode dd aimg_decode + img_encode dd aimg_encode + img_create dd aimg_create + img_destroy dd aimg_destroy + img_destroy_layer dd aimg_destroy_layer + img_count dd aimg_count + img_lock_bits dd aimg_lock_bits + img_unlock_bits dd aimg_unlock_bits + img_flip dd aimg_flip + img_flip_layer dd aimg_flip_layer + img_rotate dd aimg_rotate + img_rotate_layer dd aimg_rotate_layer + img_draw dd aimg_draw + + dd 0,0 + alib_init1 db 'lib_init',0 + aimg_is_img db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение + aimg_info db 'img_info',0 + aimg_from_file db 'img_from_file',0 + aimg_to_file db 'img_to_file',0 + aimg_from_rgb db 'img_from_rgb',0 + aimg_to_rgb db 'img_to_rgb',0 ;преобразование изображения в данные RGB + aimg_to_rgb2 db 'img_to_rgb2',0 + aimg_decode db 'img_decode',0 ;автоматически определяет формат графических данных + aimg_encode db 'img_encode',0 + aimg_create db 'img_create',0 + aimg_destroy db 'img_destroy',0 + aimg_destroy_layer db 'img_destroy_layer',0 + aimg_count db 'img_count',0 + aimg_lock_bits db 'img_lock_bits',0 + aimg_unlock_bits db 'img_unlock_bits',0 + aimg_flip db 'img_flip',0 + aimg_flip_layer db 'img_flip_layer',0 + aimg_rotate db 'img_rotate',0 + aimg_rotate_layer db 'img_rotate_layer',0 + aimg_draw db 'img_draw',0 + +align 4 +import_proclib: + OpenDialog_Init dd aOpenDialog_Init + OpenDialog_Start dd aOpenDialog_Start + OpenDialog_Set_file_name dd aOpenDialog_Set_file_name + ;OpenDialog_Set_file_ext dd aOpenDialog_Set_file_ext +dd 0,0 + aOpenDialog_Init db 'OpenDialog_init',0 + aOpenDialog_Start db 'OpenDialog_start',0 + aOpenDialog_Set_file_name db 'OpenDialog_set_file_name',0 + ;aOpenDialog_Set_file_ext db 'OpenDialog_set_file_ext',0 + +align 4 +import_buf2d: + init dd sz_init + buf2d_create dd sz_buf2d_create + buf2d_create_f_img dd sz_buf2d_create_f_img + buf2d_clear dd sz_buf2d_clear + buf2d_draw dd sz_buf2d_draw + buf2d_delete dd sz_buf2d_delete + buf2d_resize dd sz_buf2d_resize + buf2d_line dd sz_buf2d_line + buf2d_line_sm dd sz_buf2d_line_sm + buf2d_rect_by_size dd sz_buf2d_rect_by_size + buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size + buf2d_circle dd sz_buf2d_circle + buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2 + buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2 + buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8 + buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32 + buf2d_bit_blt dd sz_buf2d_bit_blt + buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp + buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha + buf2d_curve_bezier dd sz_buf2d_curve_bezier + buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix + buf2d_draw_text dd sz_buf2d_draw_text + buf2d_crop_color dd sz_buf2d_crop_color + buf2d_flip_h dd sz_buf2d_flip_h + buf2d_flip_v dd sz_buf2d_flip_v + buf2d_offset_h dd sz_buf2d_offset_h + buf2d_flood_fill dd sz_buf2d_flood_fill + buf2d_set_pixel dd sz_buf2d_set_pixel + dd 0,0 + sz_init db 'lib_init',0 + sz_buf2d_create db 'buf2d_create',0 + sz_buf2d_create_f_img db 'buf2d_create_f_img',0 + sz_buf2d_clear db 'buf2d_clear',0 + sz_buf2d_draw db 'buf2d_draw',0 + sz_buf2d_delete db 'buf2d_delete',0 + sz_buf2d_resize db 'buf2d_resize',0 + sz_buf2d_line db 'buf2d_line',0 + sz_buf2d_line_sm db 'buf2d_line_sm',0 + sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0 + sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0 + sz_buf2d_circle db 'buf2d_circle',0 + sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0 + sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0 + sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0 + sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0 + sz_buf2d_bit_blt db 'buf2d_bit_blt',0 + sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0 + sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0 + sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0 + sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0 + sz_buf2d_draw_text db 'buf2d_draw_text',0 + sz_buf2d_crop_color db 'buf2d_crop_color',0 + sz_buf2d_flip_h db 'buf2d_flip_h',0 + sz_buf2d_flip_v db 'buf2d_flip_v',0 + sz_buf2d_offset_h db 'buf2d_offset_h',0 + sz_buf2d_flood_fill db 'buf2d_flood_fill',0 + sz_buf2d_set_pixel db 'buf2d_set_pixel',0 + +align 4 +import_box_lib: + dd sz_init1 + + init_checkbox dd sz_Init_checkbox + check_box_draw dd sz_Check_box_draw + check_box_mouse dd sz_Check_box_mouse + ;version_ch dd sz_Version_ch + + option_box_draw dd sz_Option_box_draw + option_box_mouse dd sz_Option_box_mouse + ;version_op dd sz_Version_op + + edit_box_draw dd sz_edit_box_draw + edit_box_key dd sz_edit_box_key + edit_box_mouse dd sz_edit_box_mouse + edit_box_set_text dd sz_edit_box_set_text + scrollbar_ver_draw dd sz_scrollbar_ver_draw + scrollbar_hor_draw dd sz_scrollbar_hor_draw + + progressbar_draw dd sz_progressbar_draw + progressbar_progress dd sz_progressbar_progress + + dd 0,0 + sz_init1 db 'lib_init',0 + + sz_Init_checkbox db 'init_checkbox2',0 + sz_Check_box_draw db 'check_box_draw2',0 + sz_Check_box_mouse db 'check_box_mouse2',0 + ;sz_Version_ch db 'version_ch2',0 + + sz_Option_box_draw db 'option_box_draw',0 + sz_Option_box_mouse db 'option_box_mouse',0 + ;sz_Version_op db 'version_op',0 + + sz_edit_box_draw db 'edit_box_draw',0 + sz_edit_box_key db 'edit_box_key',0 + sz_edit_box_mouse db 'edit_box_mouse',0 + sz_edit_box_set_text db 'edit_box_set_text',0 + sz_scrollbar_ver_draw db 'scrollbar_v_draw',0 + sz_scrollbar_hor_draw db 'scrollbar_h_draw',0 + + sz_progressbar_draw db 'progressbar_draw', 0 + sz_progressbar_progress db 'progressbar_progress', 0 + +align 4 +import_libkmenu: + kmenu_init dd akmenu_init + kmainmenu_draw dd akmainmenu_draw + kmainmenu_dispatch_cursorevent dd akmainmenu_dispatch_cursorevent + ksubmenu_new dd aksubmenu_new + ksubmenu_delete dd aksubmenu_delete + ksubmenu_draw dd aksubmenu_draw + ksubmenu_add dd aksubmenu_add + kmenuitem_new dd akmenuitem_new + kmenuitem_delete dd akmenuitem_delete + kmenuitem_draw dd akmenuitem_draw +dd 0,0 + akmenu_init db 'kmenu_init',0 + akmainmenu_draw db 'kmainmenu_draw',0 + akmainmenu_dispatch_cursorevent db 'kmainmenu_dispatch_cursorevent',0 + aksubmenu_new db 'ksubmenu_new',0 + aksubmenu_delete db 'ksubmenu_delete',0 + aksubmenu_draw db 'ksubmenu_draw',0 + aksubmenu_add db 'ksubmenu_add',0 + akmenuitem_new db 'kmenuitem_new',0 + akmenuitem_delete db 'kmenuitem_delete',0 + akmenuitem_draw db 'kmenuitem_draw',0 + +button_press dd 0 ;for kmenu + +align 4 +mouse_dd dd 0 +last_time dd 0 + +align 16 +sc system_colors + +align 16 +procinfo process_information + +align 4 +buf_0: dd 0 ;указатель на буфер изображения +.l: dw 15 ;+4 left +.t: dw 50 ;+6 top +.w: dd 384 ;+8 w +.h: dd 350 ;+12 h +.color: dd 0xffffd0 ;+16 color + db 24 ;+20 bit in pixel + +align 4 +buf_1: + dd 0 ;указатель на буфер изображения + dd 0 ;+4 left,top +.w: dd 0 +.h: dd 0,0,24 ;+12 color,bit in pixel + +font_h dd 0 ;высота шрифта + +;input: +; eax - число +; edi - буфер для строки +; len - длинна буфера +;output: +align 4 +proc convert_int_to_str uses eax ecx edx edi esi, len:dword + mov esi,[len] + add esi,edi + dec esi + call .str + ret +endp + +align 4 +.str: + mov ecx,10 + cmp eax,ecx + jb @f + xor edx,edx + div ecx + push edx + ;dec edi ;смещение необходимое для записи с конца строки + call .str + pop eax + @@: + cmp edi,esi + jge @f + or al,0x30 + stosb + mov byte[edi],0 ;в конец строки ставим 0, что-бы не вылазил мусор + @@: + ret + +align 4 +proc mem_copy uses ecx esi edi, destination:dword, source:dword, len:dword + cld + mov esi, [source] + mov edi, [destination] + mov ecx, [len] + rep movsb + ret +endp + +edMaxSize = 511 +edMax = 0 ;max, size, pos + +align 4 +editFileName edit_box 270,450,78, 0xffffff, 0x6a9480, 0, 0xAABBCC, 0, edMaxSize, fileNameBuffer.data, mouse_dd, 0, edMax, edMax +editCommand edit_box 150,450,121, 0xffffff, 0x6a9480, 0, 0xAABBCC, 0, edMaxSize, commandBuffer.data, mouse_dd, 0, edMax, edMax + +opt1 option_box opt_gr1, 433,64, 6,12,0xd0d0ff, 0xff, 0x80ff,txt_filename,txt_filename.end-txt_filename +opt2 option_box opt_gr1, 433,107,6,12,0xd0d0ff, 0xff, 0x80ff,txt_command,txt_command.end-txt_command +opt_gr1 dd opt1 +align 4 +opt_grlist1 dd opt1,opt2,0 ;end option group + +pb: +.value dd 0 +.left dd 0 +.top dd 0 +.width dd 0 +.height dd 0 +.style dd 0 +.min dd 0 +.max dd 0 +.back_color dd 0 +.progress_color dd 0 +.frame_color dd 0 + +fileNameBuffer: +.data: rb 512 +.size: rd 1 +fileNameBufferEnd: + +commandBuffer: +.data: rb 512 +.size: rd 1 +commandBufferEnd: + +align 16 +i_end: + rb 2048 +thread_coords: + rb 2048 +thread_scale: + rb 2048 +thread_n_file: + rb 2048 +stacktop: + sys_path rb 1024 + file_name rb 2048 + plugin_path rb 4096 + openfile_path rb 4096 + filename_area rb 256 + pi rb 1024 +mem: diff --git a/programs/other/cnc_editor/cnc_editor.asm b/programs/other/cnc_editor/cnc_editor.asm index b7184f0e2..47924f820 100644 --- a/programs/other/cnc_editor/cnc_editor.asm +++ b/programs/other/cnc_editor/cnc_editor.asm @@ -1,2419 +1,2424 @@ -use32 - org 0 - db 'MENUET01' - dd 1,start,i_end,mem,stacktop,file_name,sys_path - -include '../../macros.inc' -include '../../proc32.inc' -include '../../KOSfuncs.inc' -include '../../load_img.inc' -include '../../load_lib.mac' -include '../../develop/libraries/libs-dev/libimg/libimg.inc' -include '../../develop/libraries/box_lib/trunk/box_lib.mac' -include 'lang.inc' -include 'cnc_editor.inc' -include '../../develop/info3ds/info_fun_float.inc' - -@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load -caption db 'CNC editor 23.05.19',0 ;подпись окна - -run_file_70 FileInfoBlock - -offs_last_timer dd 0 ;последний сдвиг показаный в функции таймера - -IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3 -image_data_toolbar dd 0 ;указатель на временную память. для нужен преобразования изображения -icon_tl_sys dd 0 ;указатель на память для хранения системных иконок -icon_toolbar dd 0 ;указатель на память для хранения иконок объектов - -include 'wnd_point_coords.inc' -include 'wnd_scale.inc' -include 'wnd_new_file.inc' - -align 4 -start: - ;--- copy cmd line --- - mov esi,file_name - mov edi,openfile_path -@@: - lodsd - or eax,eax - jz @f ;выход, если 0 - stosd - jmp @b -@@: - stosd - - load_libraries l_libs_start,l_libs_end - ;проверка на сколько удачно загузилась библиотека - mov ebp,lib_0 - cmp dword [ebp+ll_struc_size-4],0 - jz @f - mcall SF_TERMINATE_PROCESS - @@: - mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors - mcall SF_SET_EVENTS_MASK,0xC0000027 - stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога - - stdcall [buf2d_create], buf_0 ;создание буфера - - ;шрифт делаем до создания панели (для экономии указателя image_data_toolbar) - include_image_file '..\..\fs\kfar\trunk\font6x9.bmp', image_data_toolbar, buf_1.w,buf_1.h - stdcall [buf2d_create_f_img], buf_1,[image_data_toolbar] ;создаем буфер - stdcall mem.Free,[image_data_toolbar] ;освобождаем память - stdcall [buf2d_conv_24_to_8], buf_1,1 ;делаем буфер прозрачности 8 бит - stdcall [buf2d_convert_text_matrix], buf_1 - mov eax,[buf_1.h] - shr eax,8 - mov [font_h],eax - - include_image_file 'toolbar.png', image_data_toolbar - - mov dword[w_scr_t1.type],1 - stdcall dword[tl_data_init], tree1 - ;системные иконки 16*16 для tree_list - include_image_file 'tl_sys_16.png', icon_tl_sys - mov eax,dword[icon_tl_sys] - mov dword[tree1.data_img_sys],eax - - include_image_file 'objects.png', icon_toolbar - mov eax,dword[icon_toolbar] - mov dword[tree1.data_img],eax - - ;*** установка времени для таймера - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov [last_time],eax - - ;open file from cmd line - cmp dword[openfile_path],0 - je @f - call but_open_file.no_dlg - @@: - -align 4 -red_win: - call draw_window - -align 4 -still: - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov ebx,[last_time] - add ebx,10 ;задержка - cmp ebx,eax - jge @f - mov ebx,eax - @@: - sub ebx,eax - mcall SF_WAIT_EVENT_TIMEOUT - cmp eax,0 - jne @f - call timer_funct - jmp still - @@: - - cmp al,1 - jz red_win - cmp al,2 - jz key - cmp al,3 - jz button - cmp al,6 - jne @f - mcall SF_THREAD_INFO,procinfo,-1 - cmp ax,word[procinfo.window_stack_position] - jne @f ;окно не активно - call mouse - @@: - jmp still - -align 4 -mouse: - push eax ebx ecx - mcall SF_MOUSE_GET,SSF_BUTTON_EXT - bt eax,8 - jnc @f - ;mouse l. but. press - call mouse_left_d - jmp .end_l - @@: - ;bt eax,0 - ;jnc @f - ;mouse l. but. move - ;call mouse_left_m - ;jmp .end_l - ;@@: - bt eax,16 - jnc .end_l - ;mouse l. but. up - call mouse_left_u - ;jmp .end_l - .end_l: - bt eax,9 - jnc @f - ;mouse r. but. press - call mouse_right_d - ;jmp .end_r - @@: - ;bt eax,1 - ;jnc @f - ;mouse r. but. move - ;call mouse_right_m - ;jmp .end_r - ;@@: - ;.end_r: - - call buf_get_mouse_coord - cmp eax,-1 - je .end0 - shl eax,1 - sub eax,[buf_0.w] - sar eax,1 - mov [mouse_prop_x],eax - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end0 - cmp [eax+Figure.OType],'Fig' - je @f - cmp [eax+Figure.OType],'Obj' - je .end1 - jmp .end0 - .end1: - mov eax,ObjData - @@: - mov ecx,eax - shl ebx,1 - sub ebx,[buf_0.h] - sar ebx,1 - mov [mouse_prop_y],ebx - - mcall SF_MOUSE_GET,SSF_SCROLL_DATA - test ax,ax - jz .end0 - finit - fld qword[zoom_plus] - fld1 - fsubp - fld st0 ;for Y coord - - ;for X coord - fild dword[mouse_prop_x] - fmulp st1,st0 - - mov ebx,eax - test ax,0x8000 - jnz .decr - ;увеличение масштаба - fchs - fild dword[ecx+Figure.MCentrX] ;add old value - fmul qword[zoom_plus] - faddp - - fld qword[ecx+Figure.MScale] - fmul qword[zoom_plus] - ;if (Figure.MScale>16.0) - ;... - jmp @f - .decr: - ;уменьшение масштаба - fild dword[ecx+Figure.MCentrX] ;add old value - fdiv qword[zoom_plus] - faddp - - fld qword[ecx+Figure.MScale] - fdiv qword[zoom_plus] - fld1 - fcomp - fstsw ax - sahf - jbe @f - ;if (Figure.MScale<1.0) - ffree st0 - fincstp - ffree st0 - fincstp - fldz ;default Figure.MCentrX - fld1 ;default Figure.MScale - mov dword[ecx+Figure.MCentrY],0 - @@: - fstp qword[ecx+Figure.MScale] - fistp dword[ecx+Figure.MCentrX] - - ;for Y coord - fild dword[mouse_prop_y] - fmulp st1,st0 - test bx,0x8000 - jnz .decr_y - ;увеличение масштаба - fild dword[ecx+Figure.MCentrY] ;add old value - fmul qword[zoom_plus] - faddp - jmp @f - .decr_y: - ;уменьшение масштаба - fchs - fild dword[ecx+Figure.MCentrY] ;add old value - fdiv qword[zoom_plus] - faddp - @@: - fistp dword[ecx+Figure.MCentrY] - - mov dword[offs_last_timer],0 - .end0: - - stdcall [tl_mouse], tree1 - pop ecx ebx eax - ret - -;output: -; eax - buffer coord X (если курсор за буфером -1) -; ebx - buffer coord Y (если курсор за буфером -1) -align 4 -proc buf_get_mouse_coord - mcall SF_MOUSE_GET,SSF_WINDOW_POSITION - cmp ax,word[buf_0.t] - jl .no_buf ;не попали в окно буфера по оси y - mov ebx,eax - shr ebx,16 - cmp bx,word[buf_0.l] - jl .no_buf ;не попали в окно буфера по оси x - - and eax,0xffff ;оставляем координату y - sub ax,word[buf_0.t] - cmp eax,[buf_0.h] - jg .no_buf - sub bx,word[buf_0.l] - cmp ebx,[buf_0.w] - jg .no_buf - xchg eax,ebx - jmp .end_f - .no_buf: - xor eax,eax - not eax - xor ebx,ebx - not ebx - .end_f: - ret -endp - -align 4 -proc timer_funct - pushad - mcall SF_SYSTEM_GET,SSF_TIME_COUNT - mov [last_time],eax - - ;просматриваем выделенный блок данных - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end_f - cmp dword[offs_last_timer],eax - je .end_f - ;если выделенный блок данных не совпадает с последним запомненным - mov dword[offs_last_timer],eax - - stdcall get_object_data,eax - or ecx,ecx - jz .end_oblo - stdcall draw_obj2d,ecx - stdcall [buf2d_draw], buf_0 - jmp .end_f - .end_oblo: - - cmp [eax+Figure.OType],'Fig' - jne .end_fblo - stdcall draw_fig2d,eax - stdcall [buf2d_draw], buf_0 - jmp .end_f - .end_fblo: - - .end_f: - - popad - ret -endp - -align 4 -draw_window: -pushad - mcall SF_REDRAW,SSF_BEGIN_DRAW - - ; *** рисование главного окна (выполняется 1 раз при запуске) *** - mov edx,[sc.work] - or edx,0x33000000 - mov edi,caption - mcall SF_CREATE_WINDOW,(20 shl 16)+599,(20 shl 16)+415 - - mcall SF_THREAD_INFO,procinfo,-1 - mov eax,dword[procinfo.box.height] - cmp eax,120 - jge @f - mov eax,120 ;min size - @@: - sub eax,65 - mov dword[tree1.box_height],eax - mov word[w_scr_t1.y_size],ax ;новые размеры скроллинга - mov ebx,dword[procinfo.box.width] - cmp ebx,270 - jge @f - mov ebx,270 - @@: - sub ebx,215 - cmp eax,dword[buf_0.h] ;смотрим размер буфера - jne @f - cmp ebx,dword[buf_0.w] - jne @f - jmp .end0 - @@: - stdcall [buf2d_resize],buf_0,ebx,eax,1 - mov eax,ObjData - mov ecx,[eax+Object.FigCount] - or ecx,ecx - jz .end0 - mov eax,[eax+Object.FigData] - xor edx,edx - .cycle0: - stdcall FigCalculateSizes,[eax+4*edx],0 - inc edx - loop .cycle0 - stdcall ObjCalculateScale,ObjData - mov dword[offs_last_timer],0 - call timer_funct - .end0: - - ; *** создание кнопок на панель *** - mcall SF_DEFINE_BUTTON,(5 shl 16)+20,(5 shl 16)+20,3, [sc.work_button] - - add ebx,25 shl 16 - mcall ,,,4 ;open - add ebx,25 shl 16 - mcall ,,,5 ;save - - add ebx,30 shl 16 - mcall ,,,6 ;captions on off - - add ebx,25 shl 16 - mcall ,,,7 ;figure move up - add ebx,25 shl 16 - mcall ,,,8 ;figure move down - - add ebx,25 shl 16 - mcall ,,,9 ;sel points dlg - - add ebx,25 shl 16 - mcall ,,,10 ;sel points move up - add ebx,25 shl 16 - mcall ,,,11 ;sel points move down - - add ebx,25 shl 16 - mcall ,,,12 ;align sel points left - add ebx,25 shl 16 - mcall ,,,13 ;align sel points right - add ebx,25 shl 16 - mcall ,,,14 ;align sel points top - add ebx,25 shl 16 - mcall ,,,15 ;align sel points bottom - add ebx,25 shl 16 - mcall ,,,16 ;optimize figure - - add ebx,30 shl 16 - mcall ,,,17 ;copy to clipboard - add ebx,25 shl 16 - mcall ,,,18 ;paste from clipboard - - add ebx,25 shl 16 - mcall ,,,19 ;sel points del - - add ebx,30 shl 16 - mcall ,,,20 ;restore zoom - - add ebx,30 shl 16 - mcall ,,,21 ;.png - - add ebx,25 shl 16 - mcall ,,,22 ;options scale - - ; *** рисование иконок на кнопках *** - mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16,(7 shl 16)+7 ;icon new - - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;icon open - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;icon save - int 0x40 - - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(30 shl 16) ;captions on off - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;figure move up - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;figure move down - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;sel points dlg - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;sel points move up - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;sel points move down - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;aling sel points left - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;aling sel points right - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;aling sel points top - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;aling sel points bottom - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;optimize figure - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(30 shl 16) ;copy to clipboard - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;paste from clipboard - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;sel points del - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(30 shl 16) ;restore zoom - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(30 shl 16) ;.png - int 0x40 - add ebx,IMAGE_TOOLBAR_ICON_SIZE - add edx,(25 shl 16) ;options scale - int 0x40 - - mov dword[w_scr_t1.all_redraw],1 - stdcall [tl_draw], tree1 - stdcall [buf2d_draw], buf_0 - - mcall SF_REDRAW,SSF_END_DRAW -popad - ret - -align 4 -key: - mcall SF_GET_KEY - cmp dword[el_focus], tree1 - jne @f - stdcall [tl_key], tree1 - jmp .end0 - @@: - - cmp ah,178 ;Up - jne @f - call but_selection_move_up - jmp .end0 - @@: - cmp ah,177 ;Down - jne @f - call but_selection_move_down - jmp .end0 - @@: - cmp ah,176 ;Left - jne @f - call but_selection_move_up - jmp .end0 - @@: - cmp ah,179 ;Right - jne @f - call but_selection_move_down - jmp .end0 - @@: - cmp ah,182 ;Delete - jne @f - call but_sel_points_del - jmp .end0 - @@: - - mov ecx,eax - mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS - bt eax,2 ;left Ctrl - jc .key_Ctrl - bt eax,3 ;right Ctrl - jc .key_Ctrl - jmp .end0 - .key_Ctrl: - cmp ch,15 ;111 ;Ctrl+O - jne @f - call but_open_file - @@: - cmp ch,19 ;115 ;Ctrl+S - jne @f - call but_save_file - @@: - cmp ch,14 ;110 ;Ctrl+N - jne @f - call but_new_file - @@: - cmp ch,1 ;97 ;Ctrl+A - jne @f - call but_sel_points_all - @@: - .end0: - jmp still - - -align 4 -button: - mcall SF_GET_BUTTON - cmp ah,3 - jne @f - call but_new_file - jmp still - @@: - cmp ah,4 - jne @f - call but_open_file - jmp still - @@: - cmp ah,5 - jne @f - call but_save_file - jmp still - @@: - cmp ah,6 - jne @f - call but_captions_on_off - jmp still - @@: - cmp ah,7 - jne @f - call but_sel_figure_move_up - jmp still - @@: - cmp ah,8 - jne @f - call but_sel_figure_move_down - jmp still - @@: - cmp ah,9 - jne @f - call but_dlg_point_coords - jmp still - @@: - cmp ah,10 - jne @f - call but_sel_points_move_up - jmp still - @@: - cmp ah,11 - jne @f - call but_sel_points_move_down - jmp still - @@: - cmp ah,12 - jne @f - call but_sel_points_align_coord_xmin - jmp still - @@: - cmp ah,13 - jne @f - call but_sel_points_align_coord_xmax - jmp still - @@: - cmp ah,14 - jne @f - call but_sel_points_align_coord_ymax - jmp still - @@: - cmp ah,15 - jne @f - call but_sel_points_align_coord_ymin - @@: - cmp ah,16 - jne @f - call but_points_optimize - jmp still - @@: - cmp ah,17 - jne @f - call but_clipboard_copy_points - jmp still - @@: - cmp ah,18 - jne @f - call but_clipboard_paste_points - jmp still - @@: - cmp ah,19 - jne @f - call but_sel_points_del - jmp still - @@: - cmp ah,20 - jne @f - call but_restore_zoom - jmp still - @@: - cmp ah,21 - jne @f - call but_save_png - jmp still - @@: - cmp ah,22 - jne @f - call but_dlg_opt_scale - jmp still - @@: - - ;cmp ah,23 - ;jne @f - ;call but_... - ;jmp still - ;@@: - cmp ah,1 - jne still -.exit: - stdcall [buf2d_delete],buf_0 - stdcall mem.Free,[image_data_toolbar] - stdcall mem.Free,[open_file_data] - mcall SF_TERMINATE_PROCESS - - -align 4 -but_new_file: - cmp byte[wnd_n_file],0 - jne .end_f -pushad - mcall SF_CREATE_THREAD,1,start_n_file,thread_n_file -popad - .end_f: - ret - -align 4 -open_file_data dd 0 ;указатель на память для открытия файлов -open_file_size dd 0 ;размер открытого файла - -align 4 -but_open_file: - copy_path open_dialog_name,communication_area_default_path,file_name,0 - pushad - mov [OpenDialog_data.type],0 - stdcall [OpenDialog_Start],OpenDialog_data - cmp [OpenDialog_data.status],2 - je .end_open_file - ;код при удачном открытии диалога - jmp .end0 -.no_dlg: ;если минуем диалог открытия файла - pushad - mov esi,openfile_path - stdcall str_len,esi - add esi,eax - @@: ;цикл для поиска начала имени файла - dec esi - cmp byte[esi],'/' - je @f - cmp byte[esi],0x5c ;'\' - je @f - cmp esi,openfile_path - jg @b - @@: - inc esi - stdcall [OpenDialog_Set_file_name],OpenDialog_data,esi ;копируем имя файла в диалог сохранения - .end0: - - mov [run_file_70.Function], SSF_GET_INFO - mov [run_file_70.Position], 0 - mov [run_file_70.Flags], 0 - mov dword[run_file_70.Count], 0 - mov dword[run_file_70.Buffer], open_b - mov byte[run_file_70+20], 0 - mov dword[run_file_70.FileName], openfile_path - mcall SF_FILE,run_file_70 - - mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах - inc ecx ;for text files - stdcall mem.ReAlloc,[open_file_data],ecx - mov [open_file_data],eax - dec ecx ;for text files - mov byte[eax+ecx],0 ;for text files - - mov [run_file_70.Function], SSF_READ_FILE - mov [run_file_70.Position], 0 - mov [run_file_70.Flags], 0 - mov dword[run_file_70.Count], ecx - m2m dword[run_file_70.Buffer], dword[open_file_data] - mov byte[run_file_70+20], 0 - mov dword[run_file_70.FileName], openfile_path - mcall SF_FILE,run_file_70 ;загружаем файл изображения - test eax,eax - jnz .end_open_file - cmp ebx,0xffffffff - je .end_open_file - - mov [open_file_size],ebx - mcall SF_SET_CAPTION,1,openfile_path - - ;--- - and dword[tree1.style],not tl_cursor_pos_limited - stdcall FileInit,[open_file_data],[open_file_size] - or dword[tree1.style], tl_cursor_pos_limited - stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер - stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране - .end_open_file: - popad - ret - -align 4 -proc but_save_file -locals - pCou dd ? - pData dd ? -endl - pushad - copy_path open_dialog_name,communication_area_default_path,file_name,0 - mov [OpenDialog_data.type],1 - stdcall [OpenDialog_Set_file_ext],OpenDialog_data,Filter.1 ;.nc - stdcall [OpenDialog_Start],OpenDialog_data - cmp [OpenDialog_data.status],2 - je .end_save_file - ;код при удачном открытии диалога - - ;*** определение примерного размера файла - call get_file_save_size - stdcall mem.ReAlloc,[open_file_data],ecx - mov [open_file_data],eax - mov [open_file_size],ecx - - ;clear memory - mov edi,eax - xor eax,eax - shr ecx,2 - rep stosd - - ;*** пишем информацию в память - mov edi,[open_file_data] - mov ebx,ObjData - mov edx,[ebx+Object.FigCount] - or edx,edx - jz .cycle1end - mov esi,[ebx+Object.FigData] -align 4 - .cycle1: ;цикл по фигурам - ;param 1 - mov eax,[esi] - or eax,eax - jz .err_save - mov eax,[eax+Figure.PoiCount] - mov [pCou],eax - or eax,eax - jnz @f - mov eax,[esi] - lea eax,[eax+Figure.Caption] - stdcall str_cat,edi,eax - stdcall str_len,edi - add edi,eax - stdcall str_cat,edi,txt_nl - @@: - cmp dword[pCou],0 - je .cycle2end - mov eax,[esi] - mov eax,[eax+Figure.PoiData] - mov [pData],eax - mov word[NumberSymbolsAD],8 -align 4 - .cycle2: ;цикл по точкам - stdcall str_cat,edi,txt_s_poi - ;param 1 - push edi esi - mov esi,[pData] - lea esi,[esi+Point.CoordX] - mov edi,Data_Double - movsd - movsd - pop esi edi - call DoubleFloat_to_String - call String_crop_0 - stdcall str_cat,edi,Data_String - stdcall str_cat,edi,txt_s_poi_Y - ;param 2 - push edi esi - mov esi,[pData] - lea esi,[esi+Point.CoordY] - mov edi,Data_Double - movsd - movsd - pop esi edi - call DoubleFloat_to_String - call String_crop_0 - stdcall str_cat,edi,Data_String - ; - stdcall str_cat,edi,txt_nl - add dword[pData],sizeof.Point - dec dword[pCou] - jnz .cycle2 - .cycle2end: - add esi,4 - dec edx - jnz .cycle1 - .cycle1end: - - jmp @f - .err_save: - notify_window_run txt_err_save_txt_file_1 - @@: - - ;*** определение параметров файла - mov edi,[open_file_data] - stdcall str_len,edi - ;;cmp eax,[open_file_size] - mov [run_file_70.Count],eax ;размер файла - - ;*** сохраняем файл - mov [run_file_70.Function], SSF_CREATE_FILE - mov [run_file_70.Position], 0 - mov [run_file_70.Flags], 0 - mov ebx, dword[open_file_data] - mov [run_file_70.Buffer], ebx - mov byte[run_file_70+20], 0 - mov dword[run_file_70.FileName], openfile_path - mcall SF_FILE,run_file_70 - or eax,eax - jz .end_save_file - or ebx,ebx - jnz .end_save_file - ;сообщение о неудачном сохранении - notify_window_run txt_err_save_txt_file_0 - .end_save_file: - popad - ret -endp - -;output: -; ecx - memory size for save file -align 4 -proc get_file_save_size uses eax ebx edx esi - mov ecx,100 ;title - mov ebx,ObjData - add ecx,50 ;object - mov edx,[ebx+Object.FigCount] - or edx,edx - jz .cycle1end - mov esi,[ebx+Object.FigData] -align 4 - .cycle1: ; цикл по фигурам - add ecx,80 ;figure - mov eax,[esi] - or eax,eax - jz @f - mov eax,[eax+Figure.PoiCount] - imul eax,70 - add ecx,eax ;points - @@: - add esi,4 - dec edx - jnz .cycle1 - .cycle1end: - ret -endp - -align 4 -but_captions_on_off: - xor dword[opt_draw],1 - mov dword[offs_last_timer],0 ;для обновления по таймеру - ret - -align 4 -but_sel_figure_move_up: - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end_fblo - cmp [eax+Figure.OType],'Fig' - jne .end_fblo - stdcall found_parent_obj,eax - or eax,eax - jz .end_f ;if not found - or ecx,ecx - jz .fig_is_0 ;если фигура в начале списка - mov ebx,[eax+Object.FigData] - mov edx,[ebx+4*ecx] ;передвигаемая фигура - mov edi,[ebx+4*ecx-4] - ;меняем фигуры местами - mov [ebx+4*ecx],edi - mov [ebx+4*ecx-4],edx - ;меняем фигуры в списке - stdcall [tl_node_move_up],tree1 - jmp .end_f - .fig_is_0: - notify_window_run txt_err_figure_is_0 - jmp .end_f - .end_fblo: - notify_window_run txt_err_no_figure_select - .end_f: - popad - ret - -align 4 -but_save_png: - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end_save_file - - stdcall get_object_data,eax - or ecx,ecx - jz .end_oblo - stdcall draw_obj2d_png,ecx - jmp .beg0 - .end_oblo: - -; cmp [eax+Figure.OType],'Fig' -; jne .end_fblo -; stdcall draw_fig2d_png,eax -; jmp .beg0 -; .end_fblo: - - jmp .end_save_file - .beg0: - copy_path open_dialog_name,communication_area_default_path,file_name,0 - mov [OpenDialog_data.type],1 - stdcall [OpenDialog_Set_file_ext],OpenDialog_data,Filter.2 ;.png - stdcall [OpenDialog_Start],OpenDialog_data - cmp [OpenDialog_data.status],1 - jne .end_save_file - ;код при удачном открытии диалога - mov dword[png_data],0 - - ;create image struct - stdcall [img_create], [buf_png.w], [buf_png.h], Image.bpp24 - mov ebx,eax - test eax,eax - jz @f - ;copy foto to image buffer - mov edi,[eax+Image.Data] - mov esi,[buf_png] - mov ecx,[buf_png.w] - mov edx,[buf_png.h] - imul ecx,edx - imul ecx,3 - shr ecx,2 ;OpenGL buffer align to 4 - rep movsd - - ;encode image - stdcall [img_encode], eax, LIBIMG_FORMAT_PNG, 0 - test eax,eax - jz @f - mov [png_data],eax - mov [png_size],ecx - @@: - stdcall [img_destroy],ebx - - ; заполняем структуру для сохранения файла - mov ebx,run_file_70 - mov dword[ebx],SSF_CREATE_FILE - mov eax,[png_size] - mov [ebx+12],eax ;file size - mov eax,[png_data] - mov [ebx+16],eax - mov dword[ebx+FileInfoBlock.FileName], openfile_path - - mcall SF_FILE,run_file_70 - test eax,eax - jnz .save_error - ;notify_window_run openfile_path - jmp @f - .save_error: - ;сообщение о неудачном сохранении - notify_window_run txt_err_save_img_file - @@: - mcall SF_SYS_MISC, SSF_MEM_FREE, [png_data] - .end_save_file: - popad - ret - -;description: -; выделенные точки сдвигаются вверх -align 4 -proc but_sel_points_move_up -locals - pObj dd ? - pFig dd ? - idFig dd ? -endl - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov [pFig],eax - stdcall sel_points_get_count,eax - or eax,eax - jz .no_point - - stdcall found_parent_obj,[pFig] - or eax,eax - jz .end_f ;if not found - mov [pObj],eax - mov [idFig],ecx - - ;проверяем выделенные точки - mov eax,[pFig] - mov ecx,[eax+Figure.PoiCount] - or ecx,ecx - jz .no_point - mov ebx,[eax+Figure.PoiData] - xor eax,eax - .cycle0: - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc @f - or eax,eax - jz .point_is_0 - stdcall point_move_up, [pObj],[pFig],[idFig],ebx;,eax - @@: - inc eax - add ebx,sizeof.Point - loop .cycle0 - - ;для обновления по таймеру - mov dword[offs_last_timer],0 - jmp .end_f - .point_is_0: - notify_window_run txt_err_poi_is_0 - jmp .end_f - .no_point: - notify_window_run txt_err_no_point_sel - .end_f: - popad - ret -endp - -;description: -; выделенные точки сдвигаются вниз -align 4 -proc but_sel_points_move_down -locals - pObj dd ? - pFig dd ? - idFig dd ? -endl - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov [pFig],eax - stdcall sel_points_get_count,eax - or eax,eax - jz .no_point - - stdcall found_parent_obj,[pFig] - or eax,eax - jz .end_f ;if not found - mov [pObj],eax - mov [idFig],ecx - - ;проверяем выделенные точки - mov eax,[pFig] - mov ecx,[eax+Figure.PoiCount] - or ecx,ecx - jz .no_point - mov ebx,ecx - dec ebx - imul ebx,sizeof.Point - add ebx,[eax+Figure.PoiData] - .cycle0: - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc @f - cmp ecx,[eax+Figure.PoiCount] - je .point_is_last - mov edi,ebx - add edi,sizeof.Point - stdcall point_move_up, [pObj],[pFig],[idFig],edi;,ecx - @@: - sub ebx,sizeof.Point - loop .cycle0 - - ;для обновления по таймеру - mov dword[offs_last_timer],0 - jmp .end_f - .point_is_last: - notify_window_run txt_err_poi_is_last - jmp .end_f - .no_point: - notify_window_run txt_err_no_point_sel - .end_f: - popad - ret -endp - -;description: -; выделение выбранной точки сдвигается вверх -align 4 -proc but_selection_move_up -locals - pFig dd ? -endl - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end_fblo - cmp [eax+Figure.OType],'Fig' - jne .end_fblo - - mov [pFig],eax - stdcall sel_points_get_count,eax - cmp eax,1 - jne .no_point - - ;проверяем выделенные точки - mov eax,[pFig] - mov ecx,[eax+Figure.PoiCount] - or ecx,ecx - jz .no_point - dec ecx - jecxz .end_f - mov ebx,[eax+Figure.PoiData] - .cycle0: - add ebx,sizeof.Point - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc @f - btr dword[ebx+Point.Prop],PROP_BIT_SELECT - bts dword[ebx+Point.Prop-sizeof.Point],PROP_BIT_SELECT - xor ecx,ecx - inc ecx ;ecx = 1 - for exit from cycle - @@: - loop .cycle0 - - ;для обновления по таймеру - mov dword[offs_last_timer],0 - jmp .end_f - .no_point: - notify_window_run txt_err_no_point_sel_1 - jmp .end_f - .end_fblo: - ;notify_window_run txt_err_no_figure_select - .end_f: - popad - ret -endp - -;description: -; выделение выбранной точки сдвигается вниз -align 4 -proc but_selection_move_down -locals - pFig dd ? -endl - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end_fblo - cmp [eax+Figure.OType],'Fig' - jne .end_fblo - - mov [pFig],eax - stdcall sel_points_get_count,eax - cmp eax,1 - jne .no_point - - ;проверяем выделенные точки - mov eax,[pFig] - mov ecx,[eax+Figure.PoiCount] - or ecx,ecx - jz .no_point - dec ecx - jecxz .end_f - mov ebx,[eax+Figure.PoiData] - .cycle0: - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc @f - btr dword[ebx+Point.Prop],PROP_BIT_SELECT - bts dword[ebx+Point.Prop+sizeof.Point],PROP_BIT_SELECT - xor ecx,ecx - inc ecx ;ecx = 1 - for exit from cycle - @@: - add ebx,sizeof.Point - loop .cycle0 - - ;для обновления по таймеру - mov dword[offs_last_timer],0 - jmp .end_f - .no_point: - notify_window_run txt_err_no_point_sel_1 - jmp .end_f - .end_fblo: - ;notify_window_run txt_err_no_figure_select - .end_f: - popad - ret -endp - -;output: -; eax - couunt new points -align 4 -proc but_clipboard_copy_points uses ebx ecx edx edi esi -locals - pData dd 0 - pBuf dd 0 -endl - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov ecx,[eax+Figure.PoiData] - mov [pData],ecx - mov ecx,[eax+Figure.PoiCount] - stdcall sel_points_get_count,eax - or eax,eax - jz .no_point - push eax - imul eax,32 ;for string 'X___.________ Y___.________^^' - stdcall mem.Alloc,eax - mov [pBuf],eax - - mov edx,eax - mov dword[edx+4],0 ;text data - mov dword[edx+8],1 ;code 866 - add edx,12 ;system buffer header size - mov dword[edx],0 - mov word[NumberSymbolsAD],8 -align 4 - .cycle2: ;цикл по точкам - mov esi,[pData] - bt dword[esi+Point.Prop],PROP_BIT_SELECT - jnc .end0 - stdcall str_cat,edx,txt_s_poi - ;param 1 - add esi,Point.CoordX - mov edi,Data_Double - movsd - movsd - call DoubleFloat_to_String - call String_crop_0 - stdcall str_cat,edx,Data_String - stdcall str_cat,edx,txt_s_poi_Y - ;param 2 - ;;mov esi,[pData] - ;;lea esi,[esi+Point.CoordY] - mov edi,Data_Double - movsd - movsd - call DoubleFloat_to_String - call String_crop_0 - stdcall str_cat,edx,Data_String - ; - stdcall str_cat,edx,txt_nl - .end0: - add dword[pData],sizeof.Point - loop .cycle2 - .cycle2end: - - mov edx,[pBuf] - add edx,12 - stdcall str_len,edx - sub edx,12 - mov [edx],eax - add eax,12 - mov ecx,eax - mcall SF_CLIPBOARD,SSF_WRITE_CB ;,ecx,edx - stdcall mem.Free,[pBuf] - pop eax - - .no_point: - ret -endp - -;output: -; eax - couunt new points -align 4 -proc but_clipboard_paste_points uses ebx ecx edx esi edi -locals - pFig dd ? - nCount dd ? -endl - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .end0 - cmp [eax+Figure.OType],'Fig' - jne .end0 - - mov [pFig],eax - - mcall SF_CLIPBOARD,SSF_GET_SLOT_COUNT - cmp eax,1 - jl .end0 - - mov esi,eax - .cycle0: ;обратный цикл по слотам - dec esi ;номер текущего, проверяемого слота - mcall SF_CLIPBOARD,SSF_READ_CB,esi - cmp eax,1 - je .end0 - cmp eax,-1 - je .end0 - mov ecx,dword[eax] - cmp ecx,5 ;min text size - jl .end0 - cmp dword[eax+4],0 ;text - je @f - cmp esi,1 - jge .cycle0 ;если в буфере не текст, а слотов в буфере несколько, пробуем перейти к верхнему слоту - jmp .end0 - @@: - - mov esi,eax - add esi,12 ;смещение начала текста в буфере - stdcall get_max_points - or eax,eax - jz .end_f - mov [nCount],eax - mov ebx,[pFig] - mov edi,[ebx+Figure.PoiCount] - add [ebx+Figure.PoiCount],eax - add eax,edi - imul eax,sizeof.Point - stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax - mov [ebx+Figure.PoiData],eax - - mov ecx,edi - mov edx,eax -align 4 - .cycle1: ;цикл для снятия выделения со старых точек - btr dword[edx+Point.Prop],PROP_BIT_SELECT - add edx,sizeof.Point - loop .cycle1 - - mov ecx,[nCount] - imul edi,sizeof.Point - add edi,eax - finit -align 4 - .cycle2: ;цикл для добавления новых точек - stdcall PointInit,edi - or eax,eax - jz .cycle2end - bts dword[edi+Point.Prop],PROP_BIT_SELECT - add edi,sizeof.Point - loop .cycle2 - .cycle2end: - or ecx,ecx - jz .end1 - ;уменьшаем объем памяти выделенный для точек - sub [ebx+Figure.PoiCount],ecx - mov eax,[ebx+Figure.PoiCount] - imul eax,sizeof.Point - stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax - mov [ebx+Figure.PoiData],eax - .end1: - stdcall found_parent_obj,ebx ;get figure number in ecx - stdcall figure_update_coords,ObjData,ecx - - mov eax,[nCount] - mov dword[offs_last_timer],0 - jmp .end_f - .end0: - xor eax,eax - .end_f: - ret -endp - -align 4 -proc but_sel_points_del -locals - pFig dd ? - nDel dd ? ;need delete -endl - pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov [pFig],eax - stdcall sel_points_get_count,eax - or eax,eax - jz .no_point - mov [nDel],eax - - ;проверяем выделенные точки - mov ebx,[pFig] - mov ecx,[ebx+Figure.PoiCount] - or ecx,ecx - jz .no_point - - cmp ecx,eax - jle .no_all - - stdcall found_parent_obj,[pFig] - or eax,eax - jz .end_f ;if not found - mov edi,[ebx+Figure.PoiData] - mov edx,[ebx+Figure.PoiCount] - imul edx,sizeof.Point - add edx,edi - - .cycle0: ;1-я выделенная точка - cmp edi,edx - jge .end0 - bt dword[edi+Point.Prop],PROP_BIT_SELECT - jc .cycle0end - add edi,sizeof.Point - jmp .cycle0 - .cycle0end: - - mov esi,edi ;следущая 1-я не выделенная точка - add esi,sizeof.Point - .cycle1: - cmp esi,edx - jge .end0 - bt dword[esi+Point.Prop],PROP_BIT_SELECT - jnc .cycle1end - add esi,sizeof.Point - jmp .cycle1 - .cycle1end: - - mov ecx,sizeof.Point - rep movsb ;замена выделенной точки - bts dword[esi+Point.Prop-sizeof.Point],PROP_BIT_SELECT ;ставим выделение на точку, что-бы потом ее удалить - - jmp .cycle0 - .end0: - - ;обновление памяти - mov eax,[ebx+Figure.PoiCount] - sub eax,[nDel] - mov [ebx+Figure.PoiCount],eax - imul eax,sizeof.Point - stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax - mov [ebx+Figure.PoiData],eax - - ;перерасчет размеров фигуры - stdcall found_parent_obj,ebx ;get figure number in ecx - stdcall figure_update_coords,ObjData,ecx - - ;для обновления по таймеру - mov dword[offs_last_timer],0 - jmp .end_f - - .no_all: - notify_window_run txt_err_no_point_del - jmp .end_f - .no_point: - notify_window_run txt_err_no_point_sel - .end_f: - popad - ret -endp - -align 4 -proc but_sel_points_all uses eax ecx - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov ecx,[eax+Figure.PoiCount] - or ecx,ecx - jz .no_point - mov eax,[eax+Figure.PoiData] - .cycle0: ;цикл для выделенния точек - bts dword[eax+Point.Prop],PROP_BIT_SELECT - add eax,sizeof.Point - loop .cycle0 - ;для обновления по таймеру - mov dword[offs_last_timer],0 - .no_point: - ret -endp - -align 4 -proc but_sel_points_align_coord_xmin -pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov ebx,eax - stdcall sel_points_get_count,eax - cmp eax,1 - jle .no_point - mov ecx,[ebx+Figure.PoiCount] - or ecx,ecx - jz .no_point - cmp eax,ecx - je .no_point ;если выделенны все точки, что-бы не портить контур - - mov edx,ecx - imul edx,sizeof.Point - mov ebx,[ebx+Figure.PoiData] - add edx,ebx -align 4 - .cycle0: ;1-я выделенная точка - cmp ebx,edx - jge .no_point - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jc .cycle0end - add ebx,sizeof.Point - jmp .cycle0 - .cycle0end: - lea esi,[ebx+Point.CoordX] - mov edi,Data_Double - movsd - movsd - finit - fld qword[Data_Double] -align 4 - .cycle1: ;цикл для нахождения min(Point.CoordX) - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc .no_sel - fcom qword[ebx+Point.CoordX] - fstsw ax - sahf - jbe .no_sel - ;if (st0>Point.CoordX) - ffree st0 - fincstp - fld qword[ebx+Point.CoordX] - .no_sel: - add ebx,sizeof.Point - cmp ebx,edx - jl .cycle1 - fstp qword[Data_Double] -align 4 - .cycle2: ;цикл для присваивания всем Point.CoordX = min(Point.CoordX) - sub edx,sizeof.Point - bt dword[edx+Point.Prop],PROP_BIT_SELECT - jnc @f - mov esi,Data_Double - lea edi,[edx+Point.CoordX] - movsd - movsd - @@: - loop .cycle2 - ;для обновления по таймеру - mov dword[offs_last_timer],0 - .no_point: -popad - ret -endp - -align 4 -proc but_sel_points_align_coord_ymin -pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov ebx,eax - stdcall sel_points_get_count,eax - cmp eax,1 - jle .no_point - mov ecx,[ebx+Figure.PoiCount] - or ecx,ecx - jz .no_point - cmp eax,ecx - je .no_point ;если выделенны все точки, что-бы не портить контур - - mov edx,ecx - imul edx,sizeof.Point - mov ebx,[ebx+Figure.PoiData] - add edx,ebx -align 4 - .cycle0: ;1-я выделенная точка - cmp ebx,edx - jge .no_point - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jc .cycle0end - add ebx,sizeof.Point - jmp .cycle0 - .cycle0end: - lea esi,[ebx+Point.CoordY] - mov edi,Data_Double - movsd - movsd - finit - fld qword[Data_Double] -align 4 - .cycle1: ;цикл для нахождения min(Point.CoordY) - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc .no_sel - fcom qword[ebx+Point.CoordY] - fstsw ax - sahf - jbe .no_sel - ;if (st0>Point.CoordY) - ffree st0 - fincstp - fld qword[ebx+Point.CoordY] - .no_sel: - add ebx,sizeof.Point - cmp ebx,edx - jl .cycle1 - fstp qword[Data_Double] -align 4 - .cycle2: ;цикл для присваивания всем Point.CoordY = min(Point.CoordY) - sub edx,sizeof.Point - bt dword[edx+Point.Prop],PROP_BIT_SELECT - jnc @f - mov esi,Data_Double - lea edi,[edx+Point.CoordY] - movsd - movsd - @@: - loop .cycle2 - ;для обновления по таймеру - mov dword[offs_last_timer],0 - .no_point: -popad - ret -endp - -align 4 -proc but_sel_points_align_coord_xmax -pushad - stdcall [tl_node_get_data],tree1 - or eax,eax - jz .no_point - cmp [eax+Figure.OType],'Fig' - jne .no_point - - mov ebx,eax - stdcall sel_points_get_count,eax - cmp eax,1 - jle .no_point - mov ecx,[ebx+Figure.PoiCount] - or ecx,ecx - jz .no_point - cmp eax,ecx - je .no_point ;если выделенны все точки, что-бы не портить контур - - mov edx,ecx - imul edx,sizeof.Point - mov ebx,[ebx+Figure.PoiData] - add edx,ebx -align 4 - .cycle0: ;1-я выделенная точка - cmp ebx,edx - jge .no_point - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jc .cycle0end - add ebx,sizeof.Point - jmp .cycle0 - .cycle0end: - lea esi,[ebx+Point.CoordX] - mov edi,Data_Double - movsd - movsd - finit - fld qword[Data_Double] -align 4 - .cycle1: ;цикл для нахождения max(Point.CoordX) - bt dword[ebx+Point.Prop],PROP_BIT_SELECT - jnc .no_sel - fcom qword[ebx+Point.CoordX] - fstsw ax - sahf - jae .no_sel - ;if (st0'9' и <'A' - .us1: ;составное условие - cmp bl,'F' - jle .us2 - cmp bl,'a' - jl @f ;отсеиваем символы >'F' и <'a' - sub bl,32 ;переводим символы в верхний регистр, для упрощения их последущей обработки - .us2: ;составное условие - sub bl,'0' - cmp bl,9 - jle .cor1 - sub bl,7 ;convert 'A' to '10' - .cor1: - shl eax,4 - add eax,ebx - inc esi - jmp .cycle_16 - @@: - cmp ecx,0 ;если число отрицательное - jne @f - sub ecx,eax - mov eax,ecx - @@: - ret -endp - - -;данные для диалога открытия файлов -align 4 -OpenDialog_data: -.type dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию -.procinfo dd procinfo ;+4 -.com_area_name dd communication_area_name ;+8 -.com_area dd 0 ;+12 -.opendir_path dd plugin_path ;+16 -.dir_default_path dd default_dir ;+20 -.start_path dd file_name ;+24 путь к диалогу открытия файлов -.draw_window dd draw_window ;+28 -.status dd 0 ;+32 -.openfile_path dd openfile_path ;+36 путь к открываемому файлу -.filename_area dd filename_area ;+40 -.filter_area dd Filter -.x: -.x_size dw 420 ;+48 ; Window X size -.x_start dw 10 ;+50 ; Window X position -.y: -.y_size dw 320 ;+52 ; Window y size -.y_start dw 10 ;+54 ; Window Y position - -default_dir db '/sys',0 - -communication_area_name: - db 'FFFFFFFF_open_dialog',0 -open_dialog_name: - db 'opendial',0 -communication_area_default_path: - db '/sys/File managers/',0 - -Filter: -dd Filter.end - Filter ;.1 -.1: db 'NC',0 -.2: db 'PNG',0 -.end: -db 0 - - -align 4 -system_dir_0 db '/sys/lib/' -lib_name_0 db 'proc_lib.obj',0 -system_dir_1 db '/sys/lib/' -lib_name_1 db 'libimg.obj',0 -system_dir_2 db '/sys/lib/' -lib_name_2 db 'buf2d.obj',0 -system_dir_3 db '/sys/lib/' -lib_name_3 db 'box_lib.obj',0 - -align 4 -l_libs_start: - lib_0 l_libs lib_name_0, file_name, system_dir_0, import_proclib - lib_1 l_libs lib_name_1, file_name, system_dir_1, import_libimg - lib_2 l_libs lib_name_2, library_path, system_dir_2, import_buf2d - lib_3 l_libs lib_name_3, file_name, system_dir_3, import_box_lib -l_libs_end: - -align 4 -import_libimg: - dd alib_init1 - img_is_img dd aimg_is_img - img_info dd aimg_info - img_from_file dd aimg_from_file - img_to_file dd aimg_to_file - img_from_rgb dd aimg_from_rgb - img_to_rgb dd aimg_to_rgb - img_to_rgb2 dd aimg_to_rgb2 - img_decode dd aimg_decode - img_encode dd aimg_encode - img_create dd aimg_create - img_destroy dd aimg_destroy - img_destroy_layer dd aimg_destroy_layer - img_count dd aimg_count - img_lock_bits dd aimg_lock_bits - img_unlock_bits dd aimg_unlock_bits - img_flip dd aimg_flip - img_flip_layer dd aimg_flip_layer - img_rotate dd aimg_rotate - img_rotate_layer dd aimg_rotate_layer - img_draw dd aimg_draw - - dd 0,0 - alib_init1 db 'lib_init',0 - aimg_is_img db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение - aimg_info db 'img_info',0 - aimg_from_file db 'img_from_file',0 - aimg_to_file db 'img_to_file',0 - aimg_from_rgb db 'img_from_rgb',0 - aimg_to_rgb db 'img_to_rgb',0 ;преобразование изображения в данные RGB - aimg_to_rgb2 db 'img_to_rgb2',0 - aimg_decode db 'img_decode',0 ;автоматически определяет формат графических данных - aimg_encode db 'img_encode',0 - aimg_create db 'img_create',0 - aimg_destroy db 'img_destroy',0 - aimg_destroy_layer db 'img_destroy_layer',0 - aimg_count db 'img_count',0 - aimg_lock_bits db 'img_lock_bits',0 - aimg_unlock_bits db 'img_unlock_bits',0 - aimg_flip db 'img_flip',0 - aimg_flip_layer db 'img_flip_layer',0 - aimg_rotate db 'img_rotate',0 - aimg_rotate_layer db 'img_rotate_layer',0 - aimg_draw db 'img_draw',0 - -align 4 -import_proclib: - OpenDialog_Init dd aOpenDialog_Init - OpenDialog_Start dd aOpenDialog_Start - OpenDialog_Set_file_name dd aOpenDialog_Set_file_name - OpenDialog_Set_file_ext dd aOpenDialog_Set_file_ext -dd 0,0 - aOpenDialog_Init db 'OpenDialog_init',0 - aOpenDialog_Start db 'OpenDialog_start',0 - aOpenDialog_Set_file_name db 'OpenDialog_set_file_name',0 - aOpenDialog_Set_file_ext db 'OpenDialog_set_file_ext',0 - -align 4 -import_buf2d: - init dd sz_init - buf2d_create dd sz_buf2d_create - buf2d_create_f_img dd sz_buf2d_create_f_img - buf2d_clear dd sz_buf2d_clear - buf2d_draw dd sz_buf2d_draw - buf2d_delete dd sz_buf2d_delete - buf2d_resize dd sz_buf2d_resize - buf2d_line dd sz_buf2d_line - buf2d_line_sm dd sz_buf2d_line_sm - buf2d_rect_by_size dd sz_buf2d_rect_by_size - buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size - buf2d_circle dd sz_buf2d_circle - buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2 - buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2 - buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8 - buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32 - buf2d_bit_blt dd sz_buf2d_bit_blt - buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp - buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha - buf2d_curve_bezier dd sz_buf2d_curve_bezier - buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix - buf2d_draw_text dd sz_buf2d_draw_text - buf2d_crop_color dd sz_buf2d_crop_color - buf2d_flip_h dd sz_buf2d_flip_h - buf2d_flip_v dd sz_buf2d_flip_v - buf2d_offset_h dd sz_buf2d_offset_h - buf2d_flood_fill dd sz_buf2d_flood_fill - buf2d_set_pixel dd sz_buf2d_set_pixel - dd 0,0 - sz_init db 'lib_init',0 - sz_buf2d_create db 'buf2d_create',0 - sz_buf2d_create_f_img db 'buf2d_create_f_img',0 - sz_buf2d_clear db 'buf2d_clear',0 - sz_buf2d_draw db 'buf2d_draw',0 - sz_buf2d_delete db 'buf2d_delete',0 - sz_buf2d_resize db 'buf2d_resize',0 - sz_buf2d_line db 'buf2d_line',0 - sz_buf2d_line_sm db 'buf2d_line_sm',0 - sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0 - sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0 - sz_buf2d_circle db 'buf2d_circle',0 - sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0 - sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0 - sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0 - sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0 - sz_buf2d_bit_blt db 'buf2d_bit_blt',0 - sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0 - sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0 - sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0 - sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0 - sz_buf2d_draw_text db 'buf2d_draw_text',0 - sz_buf2d_crop_color db 'buf2d_crop_color',0 - sz_buf2d_flip_h db 'buf2d_flip_h',0 - sz_buf2d_flip_v db 'buf2d_flip_v',0 - sz_buf2d_offset_h db 'buf2d_offset_h',0 - sz_buf2d_flood_fill db 'buf2d_flood_fill',0 - sz_buf2d_set_pixel db 'buf2d_set_pixel',0 - -align 4 -import_box_lib: - dd sz_init1 - - init_checkbox dd sz_Init_checkbox - check_box_draw dd sz_Check_box_draw - check_box_mouse dd sz_Check_box_mouse - ;version_ch dd sz_Version_ch - - option_box_draw dd sz_Option_box_draw - option_box_mouse dd sz_Option_box_mouse - ;version_op dd sz_Version_op - - edit_box_draw dd sz_edit_box_draw - edit_box_key dd sz_edit_box_key - edit_box_mouse dd sz_edit_box_mouse - edit_box_set_text dd sz_edit_box_set_text - scrollbar_ver_draw dd sz_scrollbar_ver_draw - scrollbar_hor_draw dd sz_scrollbar_hor_draw - - tl_data_init dd sz_tl_data_init - tl_data_clear dd sz_tl_data_clear - tl_info_clear dd sz_tl_info_clear - tl_key dd sz_tl_key - tl_mouse dd sz_tl_mouse - tl_draw dd sz_tl_draw - tl_info_undo dd sz_tl_info_undo - tl_info_redo dd sz_tl_info_redo - tl_node_add dd sz_tl_node_add - tl_node_set_data dd sz_tl_node_set_data - tl_node_get_data dd sz_tl_node_get_data - tl_node_delete dd sz_tl_node_delete - tl_node_move_up dd sz_tl_node_move_up - tl_node_move_down dd sz_tl_node_move_down - tl_cur_beg dd sz_tl_cur_beg - tl_cur_next dd sz_tl_cur_next - tl_cur_perv dd sz_tl_cur_perv - tl_node_close_open dd sz_tl_node_close_open - tl_node_lev_inc dd sz_tl_node_lev_inc - tl_node_lev_dec dd sz_tl_node_lev_dec - tl_node_poi_get_info dd sz_tl_node_poi_get_info - tl_node_poi_get_next_info dd sz_tl_node_poi_get_next_info - tl_node_poi_get_data dd sz_tl_node_poi_get_data - - dd 0,0 - sz_init1 db 'lib_init',0 - - sz_Init_checkbox db 'init_checkbox2',0 - sz_Check_box_draw db 'check_box_draw2',0 - sz_Check_box_mouse db 'check_box_mouse2',0 - ;sz_Version_ch db 'version_ch2',0 - - sz_Option_box_draw db 'option_box_draw',0 - sz_Option_box_mouse db 'option_box_mouse',0 - ;sz_Version_op db 'version_op',0 - - sz_edit_box_draw db 'edit_box_draw',0 - sz_edit_box_key db 'edit_box_key',0 - sz_edit_box_mouse db 'edit_box_mouse',0 - sz_edit_box_set_text db 'edit_box_set_text',0 - sz_scrollbar_ver_draw db 'scrollbar_v_draw',0 - sz_scrollbar_hor_draw db 'scrollbar_h_draw',0 - - sz_tl_data_init db 'tl_data_init',0 - sz_tl_data_clear db 'tl_data_clear',0 - sz_tl_info_clear db 'tl_info_clear',0 - sz_tl_key db 'tl_key',0 - sz_tl_mouse db 'tl_mouse',0 - sz_tl_draw db 'tl_draw',0 - sz_tl_info_undo db 'tl_info_undo',0 - sz_tl_info_redo db 'tl_info_redo',0 - sz_tl_node_add db 'tl_node_add',0 - sz_tl_node_set_data db 'tl_node_set_data',0 - sz_tl_node_get_data db 'tl_node_get_data',0 - sz_tl_node_delete db 'tl_node_delete',0 - sz_tl_node_move_up db 'tl_node_move_up',0 - sz_tl_node_move_down db 'tl_node_move_down',0 - sz_tl_cur_beg db 'tl_cur_beg',0 - sz_tl_cur_next db 'tl_cur_next',0 - sz_tl_cur_perv db 'tl_cur_perv',0 - sz_tl_node_close_open db 'tl_node_close_open',0 - sz_tl_node_lev_inc db 'tl_node_lev_inc',0 - sz_tl_node_lev_dec db 'tl_node_lev_dec',0 - sz_tl_node_poi_get_info db 'tl_node_poi_get_info',0 - sz_tl_node_poi_get_next_info db 'tl_node_poi_get_next_info',0 - sz_tl_node_poi_get_data db 'tl_node_poi_get_data',0 - -align 4 -mouse_dd dd 0 -last_time dd 0 - -align 16 -sc system_colors - -align 16 -procinfo process_information - -align 4 -buf_0: dd 0 ;указатель на буфер изображения -.l: dw 205 ;+4 left -.t: dw 35 ;+6 top -.w: dd 384 ;+8 w -.h: dd 350 ;+12 h -.color: dd 0xffffd0 ;+16 color - db 24 ;+20 bit in pixel - -align 4 -buf_1: - dd 0 ;указатель на буфер изображения - dd 0 ;+4 left,top -.w: dd 0 -.h: dd 0,0,24 ;+12 color,bit in pixel - -font_h dd 0 ;высота шрифта - -align 4 -buf_png: - dd 0,0 -.w: dd 0 -.h: dd 0,0xffffff,24 - -align 4 -el_focus dd tree1 -tree1 tree_list size_one_list,1000+2, tl_key_no_edit+tl_draw_par_line,\ - 16,16, 0xffffff,0xb0d0ff,0x400040, 5,35,195-16,340, 16,Figure.Caption,0,\ - el_focus,w_scr_t1,0 - -align 4 -w_scr_t1 scrollbar 16,0, 3,0, 15, 100, 0,0, 0,0,0, 1 - -;input: -; eax - число -; edi - буфер для строки -; len - длинна буфера -;output: -align 4 -proc convert_int_to_str uses eax ecx edx edi esi, len:dword - mov esi,[len] - add esi,edi - dec esi - call .str - ret -endp - -align 4 -.str: - mov ecx,10 - cmp eax,ecx - jb @f - xor edx,edx - div ecx - push edx - ;dec edi ;смещение необходимое для записи с конца строки - call .str - pop eax - @@: - cmp edi,esi - jge @f - or al,0x30 - stosb - mov byte[edi],0 ;в конец строки ставим 0, что-бы не вылазил мусор - @@: - ret - -align 4 -proc mem_copy uses ecx esi edi, destination:dword, source:dword, len:dword - cld - mov esi, dword[source] - mov edi, dword[destination] - mov ecx, dword[len] - rep movsb - ret -endp - -align 16 -i_end: - rb 2048 -thread_coords: - rb 2048 -thread_scale: - rb 2048 -thread_n_file: - rb 2048 -stacktop: - sys_path rb 1024 - file_name: - rb 1024 ;4096 - library_path rb 1024 - plugin_path rb 4096 - openfile_path rb 4096 - filename_area rb 256 -mem: - +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + + +use32 + org 0 + db 'MENUET01' + dd 1,start,i_end,mem,stacktop,file_name,sys_path + +include '../../macros.inc' +include '../../proc32.inc' +include '../../KOSfuncs.inc' +include '../../load_img.inc' +include '../../load_lib.mac' +include '../../develop/libraries/libs-dev/libimg/libimg.inc' +include '../../develop/libraries/box_lib/trunk/box_lib.mac' +include 'lang.inc' +include 'cnc_editor.inc' +include '../../develop/info3ds/info_fun_float.inc' + +@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load +caption db 'CNC editor 23.05.19',0 ;подпись окна + +run_file_70 FileInfoBlock + +offs_last_timer dd 0 ;последний сдвиг показаный в функции таймера + +IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3 +image_data_toolbar dd 0 ;указатель на временную память. для нужен преобразования изображения +icon_tl_sys dd 0 ;указатель на память для хранения системных иконок +icon_toolbar dd 0 ;указатель на память для хранения иконок объектов + +include 'wnd_point_coords.inc' +include 'wnd_scale.inc' +include 'wnd_new_file.inc' + +align 4 +start: + ;--- copy cmd line --- + mov esi,file_name + mov edi,openfile_path +@@: + lodsd + or eax,eax + jz @f ;выход, если 0 + stosd + jmp @b +@@: + stosd + + load_libraries l_libs_start,l_libs_end + ;проверка на сколько удачно загузилась библиотека + mov ebp,lib_0 + cmp dword [ebp+ll_struc_size-4],0 + jz @f + mcall SF_TERMINATE_PROCESS + @@: + mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors + mcall SF_SET_EVENTS_MASK,0xC0000027 + stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога + + stdcall [buf2d_create], buf_0 ;создание буфера + + ;шрифт делаем до создания панели (для экономии указателя image_data_toolbar) + include_image_file '..\..\fs\kfar\font6x9.bmp', image_data_toolbar, buf_1.w,buf_1.h + stdcall [buf2d_create_f_img], buf_1,[image_data_toolbar] ;создаем буфер + stdcall mem.Free,[image_data_toolbar] ;освобождаем память + stdcall [buf2d_conv_24_to_8], buf_1,1 ;делаем буфер прозрачности 8 бит + stdcall [buf2d_convert_text_matrix], buf_1 + mov eax,[buf_1.h] + shr eax,8 + mov [font_h],eax + + include_image_file 'toolbar.png', image_data_toolbar + + mov dword[w_scr_t1.type],1 + stdcall dword[tl_data_init], tree1 + ;системные иконки 16*16 для tree_list + include_image_file 'tl_sys_16.png', icon_tl_sys + mov eax,dword[icon_tl_sys] + mov dword[tree1.data_img_sys],eax + + include_image_file 'objects.png', icon_toolbar + mov eax,dword[icon_toolbar] + mov dword[tree1.data_img],eax + + ;*** установка времени для таймера + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov [last_time],eax + + ;open file from cmd line + cmp dword[openfile_path],0 + je @f + call but_open_file.no_dlg + @@: + +align 4 +red_win: + call draw_window + +align 4 +still: + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov ebx,[last_time] + add ebx,10 ;задержка + cmp ebx,eax + jge @f + mov ebx,eax + @@: + sub ebx,eax + mcall SF_WAIT_EVENT_TIMEOUT + cmp eax,0 + jne @f + call timer_funct + jmp still + @@: + + cmp al,1 + jz red_win + cmp al,2 + jz key + cmp al,3 + jz button + cmp al,6 + jne @f + mcall SF_THREAD_INFO,procinfo,-1 + cmp ax,word[procinfo.window_stack_position] + jne @f ;окно не активно + call mouse + @@: + jmp still + +align 4 +mouse: + push eax ebx ecx + mcall SF_MOUSE_GET,SSF_BUTTON_EXT + bt eax,8 + jnc @f + ;mouse l. but. press + call mouse_left_d + jmp .end_l + @@: + ;bt eax,0 + ;jnc @f + ;mouse l. but. move + ;call mouse_left_m + ;jmp .end_l + ;@@: + bt eax,16 + jnc .end_l + ;mouse l. but. up + call mouse_left_u + ;jmp .end_l + .end_l: + bt eax,9 + jnc @f + ;mouse r. but. press + call mouse_right_d + ;jmp .end_r + @@: + ;bt eax,1 + ;jnc @f + ;mouse r. but. move + ;call mouse_right_m + ;jmp .end_r + ;@@: + ;.end_r: + + call buf_get_mouse_coord + cmp eax,-1 + je .end0 + shl eax,1 + sub eax,[buf_0.w] + sar eax,1 + mov [mouse_prop_x],eax + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end0 + cmp [eax+Figure.OType],'Fig' + je @f + cmp [eax+Figure.OType],'Obj' + je .end1 + jmp .end0 + .end1: + mov eax,ObjData + @@: + mov ecx,eax + shl ebx,1 + sub ebx,[buf_0.h] + sar ebx,1 + mov [mouse_prop_y],ebx + + mcall SF_MOUSE_GET,SSF_SCROLL_DATA + test ax,ax + jz .end0 + finit + fld qword[zoom_plus] + fld1 + fsubp + fld st0 ;for Y coord + + ;for X coord + fild dword[mouse_prop_x] + fmulp st1,st0 + + mov ebx,eax + test ax,0x8000 + jnz .decr + ;увеличение масштаба + fchs + fild dword[ecx+Figure.MCentrX] ;add old value + fmul qword[zoom_plus] + faddp + + fld qword[ecx+Figure.MScale] + fmul qword[zoom_plus] + ;if (Figure.MScale>16.0) + ;... + jmp @f + .decr: + ;уменьшение масштаба + fild dword[ecx+Figure.MCentrX] ;add old value + fdiv qword[zoom_plus] + faddp + + fld qword[ecx+Figure.MScale] + fdiv qword[zoom_plus] + fld1 + fcomp + fstsw ax + sahf + jbe @f + ;if (Figure.MScale<1.0) + ffree st0 + fincstp + ffree st0 + fincstp + fldz ;default Figure.MCentrX + fld1 ;default Figure.MScale + mov dword[ecx+Figure.MCentrY],0 + @@: + fstp qword[ecx+Figure.MScale] + fistp dword[ecx+Figure.MCentrX] + + ;for Y coord + fild dword[mouse_prop_y] + fmulp st1,st0 + test bx,0x8000 + jnz .decr_y + ;увеличение масштаба + fild dword[ecx+Figure.MCentrY] ;add old value + fmul qword[zoom_plus] + faddp + jmp @f + .decr_y: + ;уменьшение масштаба + fchs + fild dword[ecx+Figure.MCentrY] ;add old value + fdiv qword[zoom_plus] + faddp + @@: + fistp dword[ecx+Figure.MCentrY] + + mov dword[offs_last_timer],0 + .end0: + + stdcall [tl_mouse], tree1 + pop ecx ebx eax + ret + +;output: +; eax - buffer coord X (если курсор за буфером -1) +; ebx - buffer coord Y (если курсор за буфером -1) +align 4 +proc buf_get_mouse_coord + mcall SF_MOUSE_GET,SSF_WINDOW_POSITION + cmp ax,word[buf_0.t] + jl .no_buf ;не попали в окно буфера по оси y + mov ebx,eax + shr ebx,16 + cmp bx,word[buf_0.l] + jl .no_buf ;не попали в окно буфера по оси x + + and eax,0xffff ;оставляем координату y + sub ax,word[buf_0.t] + cmp eax,[buf_0.h] + jg .no_buf + sub bx,word[buf_0.l] + cmp ebx,[buf_0.w] + jg .no_buf + xchg eax,ebx + jmp .end_f + .no_buf: + xor eax,eax + not eax + xor ebx,ebx + not ebx + .end_f: + ret +endp + +align 4 +proc timer_funct + pushad + mcall SF_SYSTEM_GET,SSF_TIME_COUNT + mov [last_time],eax + + ;просматриваем выделенный блок данных + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end_f + cmp dword[offs_last_timer],eax + je .end_f + ;если выделенный блок данных не совпадает с последним запомненным + mov dword[offs_last_timer],eax + + stdcall get_object_data,eax + or ecx,ecx + jz .end_oblo + stdcall draw_obj2d,ecx + stdcall [buf2d_draw], buf_0 + jmp .end_f + .end_oblo: + + cmp [eax+Figure.OType],'Fig' + jne .end_fblo + stdcall draw_fig2d,eax + stdcall [buf2d_draw], buf_0 + jmp .end_f + .end_fblo: + + .end_f: + + popad + ret +endp + +align 4 +draw_window: +pushad + mcall SF_REDRAW,SSF_BEGIN_DRAW + + ; *** рисование главного окна (выполняется 1 раз при запуске) *** + mov edx,[sc.work] + or edx,0x33000000 + mov edi,caption + mcall SF_CREATE_WINDOW,(20 shl 16)+599,(20 shl 16)+415 + + mcall SF_THREAD_INFO,procinfo,-1 + mov eax,dword[procinfo.box.height] + cmp eax,120 + jge @f + mov eax,120 ;min size + @@: + sub eax,65 + mov dword[tree1.box_height],eax + mov word[w_scr_t1.y_size],ax ;новые размеры скроллинга + mov ebx,dword[procinfo.box.width] + cmp ebx,270 + jge @f + mov ebx,270 + @@: + sub ebx,215 + cmp eax,dword[buf_0.h] ;смотрим размер буфера + jne @f + cmp ebx,dword[buf_0.w] + jne @f + jmp .end0 + @@: + stdcall [buf2d_resize],buf_0,ebx,eax,1 + mov eax,ObjData + mov ecx,[eax+Object.FigCount] + or ecx,ecx + jz .end0 + mov eax,[eax+Object.FigData] + xor edx,edx + .cycle0: + stdcall FigCalculateSizes,[eax+4*edx],0 + inc edx + loop .cycle0 + stdcall ObjCalculateScale,ObjData + mov dword[offs_last_timer],0 + call timer_funct + .end0: + + ; *** создание кнопок на панель *** + mcall SF_DEFINE_BUTTON,(5 shl 16)+20,(5 shl 16)+20,3, [sc.work_button] + + add ebx,25 shl 16 + mcall ,,,4 ;open + add ebx,25 shl 16 + mcall ,,,5 ;save + + add ebx,30 shl 16 + mcall ,,,6 ;captions on off + + add ebx,25 shl 16 + mcall ,,,7 ;figure move up + add ebx,25 shl 16 + mcall ,,,8 ;figure move down + + add ebx,25 shl 16 + mcall ,,,9 ;sel points dlg + + add ebx,25 shl 16 + mcall ,,,10 ;sel points move up + add ebx,25 shl 16 + mcall ,,,11 ;sel points move down + + add ebx,25 shl 16 + mcall ,,,12 ;align sel points left + add ebx,25 shl 16 + mcall ,,,13 ;align sel points right + add ebx,25 shl 16 + mcall ,,,14 ;align sel points top + add ebx,25 shl 16 + mcall ,,,15 ;align sel points bottom + add ebx,25 shl 16 + mcall ,,,16 ;optimize figure + + add ebx,30 shl 16 + mcall ,,,17 ;copy to clipboard + add ebx,25 shl 16 + mcall ,,,18 ;paste from clipboard + + add ebx,25 shl 16 + mcall ,,,19 ;sel points del + + add ebx,30 shl 16 + mcall ,,,20 ;restore zoom + + add ebx,30 shl 16 + mcall ,,,21 ;.png + + add ebx,25 shl 16 + mcall ,,,22 ;options scale + + ; *** рисование иконок на кнопках *** + mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16,(7 shl 16)+7 ;icon new + + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;icon open + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;icon save + int 0x40 + + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(30 shl 16) ;captions on off + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;figure move up + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;figure move down + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;sel points dlg + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;sel points move up + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;sel points move down + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;aling sel points left + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;aling sel points right + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;aling sel points top + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;aling sel points bottom + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;optimize figure + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(30 shl 16) ;copy to clipboard + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;paste from clipboard + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;sel points del + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(30 shl 16) ;restore zoom + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(30 shl 16) ;.png + int 0x40 + add ebx,IMAGE_TOOLBAR_ICON_SIZE + add edx,(25 shl 16) ;options scale + int 0x40 + + mov dword[w_scr_t1.all_redraw],1 + stdcall [tl_draw], tree1 + stdcall [buf2d_draw], buf_0 + + mcall SF_REDRAW,SSF_END_DRAW +popad + ret + +align 4 +key: + mcall SF_GET_KEY + cmp dword[el_focus], tree1 + jne @f + stdcall [tl_key], tree1 + jmp .end0 + @@: + + cmp ah,178 ;Up + jne @f + call but_selection_move_up + jmp .end0 + @@: + cmp ah,177 ;Down + jne @f + call but_selection_move_down + jmp .end0 + @@: + cmp ah,176 ;Left + jne @f + call but_selection_move_up + jmp .end0 + @@: + cmp ah,179 ;Right + jne @f + call but_selection_move_down + jmp .end0 + @@: + cmp ah,182 ;Delete + jne @f + call but_sel_points_del + jmp .end0 + @@: + + mov ecx,eax + mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS + bt eax,2 ;left Ctrl + jc .key_Ctrl + bt eax,3 ;right Ctrl + jc .key_Ctrl + jmp .end0 + .key_Ctrl: + cmp ch,15 ;111 ;Ctrl+O + jne @f + call but_open_file + @@: + cmp ch,19 ;115 ;Ctrl+S + jne @f + call but_save_file + @@: + cmp ch,14 ;110 ;Ctrl+N + jne @f + call but_new_file + @@: + cmp ch,1 ;97 ;Ctrl+A + jne @f + call but_sel_points_all + @@: + .end0: + jmp still + + +align 4 +button: + mcall SF_GET_BUTTON + cmp ah,3 + jne @f + call but_new_file + jmp still + @@: + cmp ah,4 + jne @f + call but_open_file + jmp still + @@: + cmp ah,5 + jne @f + call but_save_file + jmp still + @@: + cmp ah,6 + jne @f + call but_captions_on_off + jmp still + @@: + cmp ah,7 + jne @f + call but_sel_figure_move_up + jmp still + @@: + cmp ah,8 + jne @f + call but_sel_figure_move_down + jmp still + @@: + cmp ah,9 + jne @f + call but_dlg_point_coords + jmp still + @@: + cmp ah,10 + jne @f + call but_sel_points_move_up + jmp still + @@: + cmp ah,11 + jne @f + call but_sel_points_move_down + jmp still + @@: + cmp ah,12 + jne @f + call but_sel_points_align_coord_xmin + jmp still + @@: + cmp ah,13 + jne @f + call but_sel_points_align_coord_xmax + jmp still + @@: + cmp ah,14 + jne @f + call but_sel_points_align_coord_ymax + jmp still + @@: + cmp ah,15 + jne @f + call but_sel_points_align_coord_ymin + @@: + cmp ah,16 + jne @f + call but_points_optimize + jmp still + @@: + cmp ah,17 + jne @f + call but_clipboard_copy_points + jmp still + @@: + cmp ah,18 + jne @f + call but_clipboard_paste_points + jmp still + @@: + cmp ah,19 + jne @f + call but_sel_points_del + jmp still + @@: + cmp ah,20 + jne @f + call but_restore_zoom + jmp still + @@: + cmp ah,21 + jne @f + call but_save_png + jmp still + @@: + cmp ah,22 + jne @f + call but_dlg_opt_scale + jmp still + @@: + + ;cmp ah,23 + ;jne @f + ;call but_... + ;jmp still + ;@@: + cmp ah,1 + jne still +.exit: + stdcall [buf2d_delete],buf_0 + stdcall mem.Free,[image_data_toolbar] + stdcall mem.Free,[open_file_data] + mcall SF_TERMINATE_PROCESS + + +align 4 +but_new_file: + cmp byte[wnd_n_file],0 + jne .end_f +pushad + mcall SF_CREATE_THREAD,1,start_n_file,thread_n_file +popad + .end_f: + ret + +align 4 +open_file_data dd 0 ;указатель на память для открытия файлов +open_file_size dd 0 ;размер открытого файла + +align 4 +but_open_file: + copy_path open_dialog_name,communication_area_default_path,file_name,0 + pushad + mov [OpenDialog_data.type],0 + stdcall [OpenDialog_Start],OpenDialog_data + cmp [OpenDialog_data.status],2 + je .end_open_file + ;код при удачном открытии диалога + jmp .end0 +.no_dlg: ;если минуем диалог открытия файла + pushad + mov esi,openfile_path + stdcall str_len,esi + add esi,eax + @@: ;цикл для поиска начала имени файла + dec esi + cmp byte[esi],'/' + je @f + cmp byte[esi],0x5c ;'\' + je @f + cmp esi,openfile_path + jg @b + @@: + inc esi + stdcall [OpenDialog_Set_file_name],OpenDialog_data,esi ;копируем имя файла в диалог сохранения + .end0: + + mov [run_file_70.Function], SSF_GET_INFO + mov [run_file_70.Position], 0 + mov [run_file_70.Flags], 0 + mov dword[run_file_70.Count], 0 + mov dword[run_file_70.Buffer], open_b + mov byte[run_file_70+20], 0 + mov dword[run_file_70.FileName], openfile_path + mcall SF_FILE,run_file_70 + + mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах + inc ecx ;for text files + stdcall mem.ReAlloc,[open_file_data],ecx + mov [open_file_data],eax + dec ecx ;for text files + mov byte[eax+ecx],0 ;for text files + + mov [run_file_70.Function], SSF_READ_FILE + mov [run_file_70.Position], 0 + mov [run_file_70.Flags], 0 + mov dword[run_file_70.Count], ecx + m2m dword[run_file_70.Buffer], dword[open_file_data] + mov byte[run_file_70+20], 0 + mov dword[run_file_70.FileName], openfile_path + mcall SF_FILE,run_file_70 ;загружаем файл изображения + test eax,eax + jnz .end_open_file + cmp ebx,0xffffffff + je .end_open_file + + mov [open_file_size],ebx + mcall SF_SET_CAPTION,1,openfile_path + + ;--- + and dword[tree1.style],not tl_cursor_pos_limited + stdcall FileInit,[open_file_data],[open_file_size] + or dword[tree1.style], tl_cursor_pos_limited + stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер + stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране + .end_open_file: + popad + ret + +align 4 +proc but_save_file +locals + pCou dd ? + pData dd ? +endl + pushad + copy_path open_dialog_name,communication_area_default_path,file_name,0 + mov [OpenDialog_data.type],1 + stdcall [OpenDialog_Set_file_ext],OpenDialog_data,Filter.1 ;.nc + stdcall [OpenDialog_Start],OpenDialog_data + cmp [OpenDialog_data.status],2 + je .end_save_file + ;код при удачном открытии диалога + + ;*** определение примерного размера файла + call get_file_save_size + stdcall mem.ReAlloc,[open_file_data],ecx + mov [open_file_data],eax + mov [open_file_size],ecx + + ;clear memory + mov edi,eax + xor eax,eax + shr ecx,2 + rep stosd + + ;*** пишем информацию в память + mov edi,[open_file_data] + mov ebx,ObjData + mov edx,[ebx+Object.FigCount] + or edx,edx + jz .cycle1end + mov esi,[ebx+Object.FigData] +align 4 + .cycle1: ;цикл по фигурам + ;param 1 + mov eax,[esi] + or eax,eax + jz .err_save + mov eax,[eax+Figure.PoiCount] + mov [pCou],eax + or eax,eax + jnz @f + mov eax,[esi] + lea eax,[eax+Figure.Caption] + stdcall str_cat,edi,eax + stdcall str_len,edi + add edi,eax + stdcall str_cat,edi,txt_nl + @@: + cmp dword[pCou],0 + je .cycle2end + mov eax,[esi] + mov eax,[eax+Figure.PoiData] + mov [pData],eax + mov word[NumberSymbolsAD],8 +align 4 + .cycle2: ;цикл по точкам + stdcall str_cat,edi,txt_s_poi + ;param 1 + push edi esi + mov esi,[pData] + lea esi,[esi+Point.CoordX] + mov edi,Data_Double + movsd + movsd + pop esi edi + call DoubleFloat_to_String + call String_crop_0 + stdcall str_cat,edi,Data_String + stdcall str_cat,edi,txt_s_poi_Y + ;param 2 + push edi esi + mov esi,[pData] + lea esi,[esi+Point.CoordY] + mov edi,Data_Double + movsd + movsd + pop esi edi + call DoubleFloat_to_String + call String_crop_0 + stdcall str_cat,edi,Data_String + ; + stdcall str_cat,edi,txt_nl + add dword[pData],sizeof.Point + dec dword[pCou] + jnz .cycle2 + .cycle2end: + add esi,4 + dec edx + jnz .cycle1 + .cycle1end: + + jmp @f + .err_save: + notify_window_run txt_err_save_txt_file_1 + @@: + + ;*** определение параметров файла + mov edi,[open_file_data] + stdcall str_len,edi + ;;cmp eax,[open_file_size] + mov [run_file_70.Count],eax ;размер файла + + ;*** сохраняем файл + mov [run_file_70.Function], SSF_CREATE_FILE + mov [run_file_70.Position], 0 + mov [run_file_70.Flags], 0 + mov ebx, dword[open_file_data] + mov [run_file_70.Buffer], ebx + mov byte[run_file_70+20], 0 + mov dword[run_file_70.FileName], openfile_path + mcall SF_FILE,run_file_70 + or eax,eax + jz .end_save_file + or ebx,ebx + jnz .end_save_file + ;сообщение о неудачном сохранении + notify_window_run txt_err_save_txt_file_0 + .end_save_file: + popad + ret +endp + +;output: +; ecx - memory size for save file +align 4 +proc get_file_save_size uses eax ebx edx esi + mov ecx,100 ;title + mov ebx,ObjData + add ecx,50 ;object + mov edx,[ebx+Object.FigCount] + or edx,edx + jz .cycle1end + mov esi,[ebx+Object.FigData] +align 4 + .cycle1: ; цикл по фигурам + add ecx,80 ;figure + mov eax,[esi] + or eax,eax + jz @f + mov eax,[eax+Figure.PoiCount] + imul eax,70 + add ecx,eax ;points + @@: + add esi,4 + dec edx + jnz .cycle1 + .cycle1end: + ret +endp + +align 4 +but_captions_on_off: + xor dword[opt_draw],1 + mov dword[offs_last_timer],0 ;для обновления по таймеру + ret + +align 4 +but_sel_figure_move_up: + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end_fblo + cmp [eax+Figure.OType],'Fig' + jne .end_fblo + stdcall found_parent_obj,eax + or eax,eax + jz .end_f ;if not found + or ecx,ecx + jz .fig_is_0 ;если фигура в начале списка + mov ebx,[eax+Object.FigData] + mov edx,[ebx+4*ecx] ;передвигаемая фигура + mov edi,[ebx+4*ecx-4] + ;меняем фигуры местами + mov [ebx+4*ecx],edi + mov [ebx+4*ecx-4],edx + ;меняем фигуры в списке + stdcall [tl_node_move_up],tree1 + jmp .end_f + .fig_is_0: + notify_window_run txt_err_figure_is_0 + jmp .end_f + .end_fblo: + notify_window_run txt_err_no_figure_select + .end_f: + popad + ret + +align 4 +but_save_png: + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end_save_file + + stdcall get_object_data,eax + or ecx,ecx + jz .end_oblo + stdcall draw_obj2d_png,ecx + jmp .beg0 + .end_oblo: + +; cmp [eax+Figure.OType],'Fig' +; jne .end_fblo +; stdcall draw_fig2d_png,eax +; jmp .beg0 +; .end_fblo: + + jmp .end_save_file + .beg0: + copy_path open_dialog_name,communication_area_default_path,file_name,0 + mov [OpenDialog_data.type],1 + stdcall [OpenDialog_Set_file_ext],OpenDialog_data,Filter.2 ;.png + stdcall [OpenDialog_Start],OpenDialog_data + cmp [OpenDialog_data.status],1 + jne .end_save_file + ;код при удачном открытии диалога + mov dword[png_data],0 + + ;create image struct + stdcall [img_create], [buf_png.w], [buf_png.h], Image.bpp24 + mov ebx,eax + test eax,eax + jz @f + ;copy foto to image buffer + mov edi,[eax+Image.Data] + mov esi,[buf_png] + mov ecx,[buf_png.w] + mov edx,[buf_png.h] + imul ecx,edx + imul ecx,3 + shr ecx,2 ;OpenGL buffer align to 4 + rep movsd + + ;encode image + stdcall [img_encode], eax, LIBIMG_FORMAT_PNG, 0 + test eax,eax + jz @f + mov [png_data],eax + mov [png_size],ecx + @@: + stdcall [img_destroy],ebx + + ; заполняем структуру для сохранения файла + mov ebx,run_file_70 + mov dword[ebx],SSF_CREATE_FILE + mov eax,[png_size] + mov [ebx+12],eax ;file size + mov eax,[png_data] + mov [ebx+16],eax + mov dword[ebx+FileInfoBlock.FileName], openfile_path + + mcall SF_FILE,run_file_70 + test eax,eax + jnz .save_error + ;notify_window_run openfile_path + jmp @f + .save_error: + ;сообщение о неудачном сохранении + notify_window_run txt_err_save_img_file + @@: + mcall SF_SYS_MISC, SSF_MEM_FREE, [png_data] + .end_save_file: + popad + ret + +;description: +; выделенные точки сдвигаются вверх +align 4 +proc but_sel_points_move_up +locals + pObj dd ? + pFig dd ? + idFig dd ? +endl + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov [pFig],eax + stdcall sel_points_get_count,eax + or eax,eax + jz .no_point + + stdcall found_parent_obj,[pFig] + or eax,eax + jz .end_f ;if not found + mov [pObj],eax + mov [idFig],ecx + + ;проверяем выделенные точки + mov eax,[pFig] + mov ecx,[eax+Figure.PoiCount] + or ecx,ecx + jz .no_point + mov ebx,[eax+Figure.PoiData] + xor eax,eax + .cycle0: + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc @f + or eax,eax + jz .point_is_0 + stdcall point_move_up, [pObj],[pFig],[idFig],ebx;,eax + @@: + inc eax + add ebx,sizeof.Point + loop .cycle0 + + ;для обновления по таймеру + mov dword[offs_last_timer],0 + jmp .end_f + .point_is_0: + notify_window_run txt_err_poi_is_0 + jmp .end_f + .no_point: + notify_window_run txt_err_no_point_sel + .end_f: + popad + ret +endp + +;description: +; выделенные точки сдвигаются вниз +align 4 +proc but_sel_points_move_down +locals + pObj dd ? + pFig dd ? + idFig dd ? +endl + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov [pFig],eax + stdcall sel_points_get_count,eax + or eax,eax + jz .no_point + + stdcall found_parent_obj,[pFig] + or eax,eax + jz .end_f ;if not found + mov [pObj],eax + mov [idFig],ecx + + ;проверяем выделенные точки + mov eax,[pFig] + mov ecx,[eax+Figure.PoiCount] + or ecx,ecx + jz .no_point + mov ebx,ecx + dec ebx + imul ebx,sizeof.Point + add ebx,[eax+Figure.PoiData] + .cycle0: + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc @f + cmp ecx,[eax+Figure.PoiCount] + je .point_is_last + mov edi,ebx + add edi,sizeof.Point + stdcall point_move_up, [pObj],[pFig],[idFig],edi;,ecx + @@: + sub ebx,sizeof.Point + loop .cycle0 + + ;для обновления по таймеру + mov dword[offs_last_timer],0 + jmp .end_f + .point_is_last: + notify_window_run txt_err_poi_is_last + jmp .end_f + .no_point: + notify_window_run txt_err_no_point_sel + .end_f: + popad + ret +endp + +;description: +; выделение выбранной точки сдвигается вверх +align 4 +proc but_selection_move_up +locals + pFig dd ? +endl + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end_fblo + cmp [eax+Figure.OType],'Fig' + jne .end_fblo + + mov [pFig],eax + stdcall sel_points_get_count,eax + cmp eax,1 + jne .no_point + + ;проверяем выделенные точки + mov eax,[pFig] + mov ecx,[eax+Figure.PoiCount] + or ecx,ecx + jz .no_point + dec ecx + jecxz .end_f + mov ebx,[eax+Figure.PoiData] + .cycle0: + add ebx,sizeof.Point + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc @f + btr dword[ebx+Point.Prop],PROP_BIT_SELECT + bts dword[ebx+Point.Prop-sizeof.Point],PROP_BIT_SELECT + xor ecx,ecx + inc ecx ;ecx = 1 - for exit from cycle + @@: + loop .cycle0 + + ;для обновления по таймеру + mov dword[offs_last_timer],0 + jmp .end_f + .no_point: + notify_window_run txt_err_no_point_sel_1 + jmp .end_f + .end_fblo: + ;notify_window_run txt_err_no_figure_select + .end_f: + popad + ret +endp + +;description: +; выделение выбранной точки сдвигается вниз +align 4 +proc but_selection_move_down +locals + pFig dd ? +endl + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end_fblo + cmp [eax+Figure.OType],'Fig' + jne .end_fblo + + mov [pFig],eax + stdcall sel_points_get_count,eax + cmp eax,1 + jne .no_point + + ;проверяем выделенные точки + mov eax,[pFig] + mov ecx,[eax+Figure.PoiCount] + or ecx,ecx + jz .no_point + dec ecx + jecxz .end_f + mov ebx,[eax+Figure.PoiData] + .cycle0: + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc @f + btr dword[ebx+Point.Prop],PROP_BIT_SELECT + bts dword[ebx+Point.Prop+sizeof.Point],PROP_BIT_SELECT + xor ecx,ecx + inc ecx ;ecx = 1 - for exit from cycle + @@: + add ebx,sizeof.Point + loop .cycle0 + + ;для обновления по таймеру + mov dword[offs_last_timer],0 + jmp .end_f + .no_point: + notify_window_run txt_err_no_point_sel_1 + jmp .end_f + .end_fblo: + ;notify_window_run txt_err_no_figure_select + .end_f: + popad + ret +endp + +;output: +; eax - couunt new points +align 4 +proc but_clipboard_copy_points uses ebx ecx edx edi esi +locals + pData dd 0 + pBuf dd 0 +endl + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov ecx,[eax+Figure.PoiData] + mov [pData],ecx + mov ecx,[eax+Figure.PoiCount] + stdcall sel_points_get_count,eax + or eax,eax + jz .no_point + push eax + imul eax,32 ;for string 'X___.________ Y___.________^^' + stdcall mem.Alloc,eax + mov [pBuf],eax + + mov edx,eax + mov dword[edx+4],0 ;text data + mov dword[edx+8],1 ;code 866 + add edx,12 ;system buffer header size + mov dword[edx],0 + mov word[NumberSymbolsAD],8 +align 4 + .cycle2: ;цикл по точкам + mov esi,[pData] + bt dword[esi+Point.Prop],PROP_BIT_SELECT + jnc .end0 + stdcall str_cat,edx,txt_s_poi + ;param 1 + add esi,Point.CoordX + mov edi,Data_Double + movsd + movsd + call DoubleFloat_to_String + call String_crop_0 + stdcall str_cat,edx,Data_String + stdcall str_cat,edx,txt_s_poi_Y + ;param 2 + ;;mov esi,[pData] + ;;lea esi,[esi+Point.CoordY] + mov edi,Data_Double + movsd + movsd + call DoubleFloat_to_String + call String_crop_0 + stdcall str_cat,edx,Data_String + ; + stdcall str_cat,edx,txt_nl + .end0: + add dword[pData],sizeof.Point + loop .cycle2 + .cycle2end: + + mov edx,[pBuf] + add edx,12 + stdcall str_len,edx + sub edx,12 + mov [edx],eax + add eax,12 + mov ecx,eax + mcall SF_CLIPBOARD,SSF_WRITE_CB ;,ecx,edx + stdcall mem.Free,[pBuf] + pop eax + + .no_point: + ret +endp + +;output: +; eax - couunt new points +align 4 +proc but_clipboard_paste_points uses ebx ecx edx esi edi +locals + pFig dd ? + nCount dd ? +endl + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .end0 + cmp [eax+Figure.OType],'Fig' + jne .end0 + + mov [pFig],eax + + mcall SF_CLIPBOARD,SSF_GET_SLOT_COUNT + cmp eax,1 + jl .end0 + + mov esi,eax + .cycle0: ;обратный цикл по слотам + dec esi ;номер текущего, проверяемого слота + mcall SF_CLIPBOARD,SSF_READ_CB,esi + cmp eax,1 + je .end0 + cmp eax,-1 + je .end0 + mov ecx,dword[eax] + cmp ecx,5 ;min text size + jl .end0 + cmp dword[eax+4],0 ;text + je @f + cmp esi,1 + jge .cycle0 ;если в буфере не текст, а слотов в буфере несколько, пробуем перейти к верхнему слоту + jmp .end0 + @@: + + mov esi,eax + add esi,12 ;смещение начала текста в буфере + stdcall get_max_points + or eax,eax + jz .end_f + mov [nCount],eax + mov ebx,[pFig] + mov edi,[ebx+Figure.PoiCount] + add [ebx+Figure.PoiCount],eax + add eax,edi + imul eax,sizeof.Point + stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax + mov [ebx+Figure.PoiData],eax + + mov ecx,edi + mov edx,eax +align 4 + .cycle1: ;цикл для снятия выделения со старых точек + btr dword[edx+Point.Prop],PROP_BIT_SELECT + add edx,sizeof.Point + loop .cycle1 + + mov ecx,[nCount] + imul edi,sizeof.Point + add edi,eax + finit +align 4 + .cycle2: ;цикл для добавления новых точек + stdcall PointInit,edi + or eax,eax + jz .cycle2end + bts dword[edi+Point.Prop],PROP_BIT_SELECT + add edi,sizeof.Point + loop .cycle2 + .cycle2end: + or ecx,ecx + jz .end1 + ;уменьшаем объем памяти выделенный для точек + sub [ebx+Figure.PoiCount],ecx + mov eax,[ebx+Figure.PoiCount] + imul eax,sizeof.Point + stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax + mov [ebx+Figure.PoiData],eax + .end1: + stdcall found_parent_obj,ebx ;get figure number in ecx + stdcall figure_update_coords,ObjData,ecx + + mov eax,[nCount] + mov dword[offs_last_timer],0 + jmp .end_f + .end0: + xor eax,eax + .end_f: + ret +endp + +align 4 +proc but_sel_points_del +locals + pFig dd ? + nDel dd ? ;need delete +endl + pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov [pFig],eax + stdcall sel_points_get_count,eax + or eax,eax + jz .no_point + mov [nDel],eax + + ;проверяем выделенные точки + mov ebx,[pFig] + mov ecx,[ebx+Figure.PoiCount] + or ecx,ecx + jz .no_point + + cmp ecx,eax + jle .no_all + + stdcall found_parent_obj,[pFig] + or eax,eax + jz .end_f ;if not found + mov edi,[ebx+Figure.PoiData] + mov edx,[ebx+Figure.PoiCount] + imul edx,sizeof.Point + add edx,edi + + .cycle0: ;1-я выделенная точка + cmp edi,edx + jge .end0 + bt dword[edi+Point.Prop],PROP_BIT_SELECT + jc .cycle0end + add edi,sizeof.Point + jmp .cycle0 + .cycle0end: + + mov esi,edi ;следущая 1-я не выделенная точка + add esi,sizeof.Point + .cycle1: + cmp esi,edx + jge .end0 + bt dword[esi+Point.Prop],PROP_BIT_SELECT + jnc .cycle1end + add esi,sizeof.Point + jmp .cycle1 + .cycle1end: + + mov ecx,sizeof.Point + rep movsb ;замена выделенной точки + bts dword[esi+Point.Prop-sizeof.Point],PROP_BIT_SELECT ;ставим выделение на точку, что-бы потом ее удалить + + jmp .cycle0 + .end0: + + ;обновление памяти + mov eax,[ebx+Figure.PoiCount] + sub eax,[nDel] + mov [ebx+Figure.PoiCount],eax + imul eax,sizeof.Point + stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax + mov [ebx+Figure.PoiData],eax + + ;перерасчет размеров фигуры + stdcall found_parent_obj,ebx ;get figure number in ecx + stdcall figure_update_coords,ObjData,ecx + + ;для обновления по таймеру + mov dword[offs_last_timer],0 + jmp .end_f + + .no_all: + notify_window_run txt_err_no_point_del + jmp .end_f + .no_point: + notify_window_run txt_err_no_point_sel + .end_f: + popad + ret +endp + +align 4 +proc but_sel_points_all uses eax ecx + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov ecx,[eax+Figure.PoiCount] + or ecx,ecx + jz .no_point + mov eax,[eax+Figure.PoiData] + .cycle0: ;цикл для выделенния точек + bts dword[eax+Point.Prop],PROP_BIT_SELECT + add eax,sizeof.Point + loop .cycle0 + ;для обновления по таймеру + mov dword[offs_last_timer],0 + .no_point: + ret +endp + +align 4 +proc but_sel_points_align_coord_xmin +pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov ebx,eax + stdcall sel_points_get_count,eax + cmp eax,1 + jle .no_point + mov ecx,[ebx+Figure.PoiCount] + or ecx,ecx + jz .no_point + cmp eax,ecx + je .no_point ;если выделенны все точки, что-бы не портить контур + + mov edx,ecx + imul edx,sizeof.Point + mov ebx,[ebx+Figure.PoiData] + add edx,ebx +align 4 + .cycle0: ;1-я выделенная точка + cmp ebx,edx + jge .no_point + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jc .cycle0end + add ebx,sizeof.Point + jmp .cycle0 + .cycle0end: + lea esi,[ebx+Point.CoordX] + mov edi,Data_Double + movsd + movsd + finit + fld qword[Data_Double] +align 4 + .cycle1: ;цикл для нахождения min(Point.CoordX) + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc .no_sel + fcom qword[ebx+Point.CoordX] + fstsw ax + sahf + jbe .no_sel + ;if (st0>Point.CoordX) + ffree st0 + fincstp + fld qword[ebx+Point.CoordX] + .no_sel: + add ebx,sizeof.Point + cmp ebx,edx + jl .cycle1 + fstp qword[Data_Double] +align 4 + .cycle2: ;цикл для присваивания всем Point.CoordX = min(Point.CoordX) + sub edx,sizeof.Point + bt dword[edx+Point.Prop],PROP_BIT_SELECT + jnc @f + mov esi,Data_Double + lea edi,[edx+Point.CoordX] + movsd + movsd + @@: + loop .cycle2 + ;для обновления по таймеру + mov dword[offs_last_timer],0 + .no_point: +popad + ret +endp + +align 4 +proc but_sel_points_align_coord_ymin +pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov ebx,eax + stdcall sel_points_get_count,eax + cmp eax,1 + jle .no_point + mov ecx,[ebx+Figure.PoiCount] + or ecx,ecx + jz .no_point + cmp eax,ecx + je .no_point ;если выделенны все точки, что-бы не портить контур + + mov edx,ecx + imul edx,sizeof.Point + mov ebx,[ebx+Figure.PoiData] + add edx,ebx +align 4 + .cycle0: ;1-я выделенная точка + cmp ebx,edx + jge .no_point + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jc .cycle0end + add ebx,sizeof.Point + jmp .cycle0 + .cycle0end: + lea esi,[ebx+Point.CoordY] + mov edi,Data_Double + movsd + movsd + finit + fld qword[Data_Double] +align 4 + .cycle1: ;цикл для нахождения min(Point.CoordY) + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc .no_sel + fcom qword[ebx+Point.CoordY] + fstsw ax + sahf + jbe .no_sel + ;if (st0>Point.CoordY) + ffree st0 + fincstp + fld qword[ebx+Point.CoordY] + .no_sel: + add ebx,sizeof.Point + cmp ebx,edx + jl .cycle1 + fstp qword[Data_Double] +align 4 + .cycle2: ;цикл для присваивания всем Point.CoordY = min(Point.CoordY) + sub edx,sizeof.Point + bt dword[edx+Point.Prop],PROP_BIT_SELECT + jnc @f + mov esi,Data_Double + lea edi,[edx+Point.CoordY] + movsd + movsd + @@: + loop .cycle2 + ;для обновления по таймеру + mov dword[offs_last_timer],0 + .no_point: +popad + ret +endp + +align 4 +proc but_sel_points_align_coord_xmax +pushad + stdcall [tl_node_get_data],tree1 + or eax,eax + jz .no_point + cmp [eax+Figure.OType],'Fig' + jne .no_point + + mov ebx,eax + stdcall sel_points_get_count,eax + cmp eax,1 + jle .no_point + mov ecx,[ebx+Figure.PoiCount] + or ecx,ecx + jz .no_point + cmp eax,ecx + je .no_point ;если выделенны все точки, что-бы не портить контур + + mov edx,ecx + imul edx,sizeof.Point + mov ebx,[ebx+Figure.PoiData] + add edx,ebx +align 4 + .cycle0: ;1-я выделенная точка + cmp ebx,edx + jge .no_point + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jc .cycle0end + add ebx,sizeof.Point + jmp .cycle0 + .cycle0end: + lea esi,[ebx+Point.CoordX] + mov edi,Data_Double + movsd + movsd + finit + fld qword[Data_Double] +align 4 + .cycle1: ;цикл для нахождения max(Point.CoordX) + bt dword[ebx+Point.Prop],PROP_BIT_SELECT + jnc .no_sel + fcom qword[ebx+Point.CoordX] + fstsw ax + sahf + jae .no_sel + ;if (st0'9' и <'A' + .us1: ;составное условие + cmp bl,'F' + jle .us2 + cmp bl,'a' + jl @f ;отсеиваем символы >'F' и <'a' + sub bl,32 ;переводим символы в верхний регистр, для упрощения их последущей обработки + .us2: ;составное условие + sub bl,'0' + cmp bl,9 + jle .cor1 + sub bl,7 ;convert 'A' to '10' + .cor1: + shl eax,4 + add eax,ebx + inc esi + jmp .cycle_16 + @@: + cmp ecx,0 ;если число отрицательное + jne @f + sub ecx,eax + mov eax,ecx + @@: + ret +endp + + +;данные для диалога открытия файлов +align 4 +OpenDialog_data: +.type dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию +.procinfo dd procinfo ;+4 +.com_area_name dd communication_area_name ;+8 +.com_area dd 0 ;+12 +.opendir_path dd plugin_path ;+16 +.dir_default_path dd default_dir ;+20 +.start_path dd file_name ;+24 путь к диалогу открытия файлов +.draw_window dd draw_window ;+28 +.status dd 0 ;+32 +.openfile_path dd openfile_path ;+36 путь к открываемому файлу +.filename_area dd filename_area ;+40 +.filter_area dd Filter +.x: +.x_size dw 420 ;+48 ; Window X size +.x_start dw 10 ;+50 ; Window X position +.y: +.y_size dw 320 ;+52 ; Window y size +.y_start dw 10 ;+54 ; Window Y position + +default_dir db '/sys',0 + +communication_area_name: + db 'FFFFFFFF_open_dialog',0 +open_dialog_name: + db 'opendial',0 +communication_area_default_path: + db '/sys/File managers/',0 + +Filter: +dd Filter.end - Filter ;.1 +.1: db 'NC',0 +.2: db 'PNG',0 +.end: +db 0 + + +align 4 +system_dir_0 db '/sys/lib/' +lib_name_0 db 'proc_lib.obj',0 +system_dir_1 db '/sys/lib/' +lib_name_1 db 'libimg.obj',0 +system_dir_2 db '/sys/lib/' +lib_name_2 db 'buf2d.obj',0 +system_dir_3 db '/sys/lib/' +lib_name_3 db 'box_lib.obj',0 + +align 4 +l_libs_start: + lib_0 l_libs lib_name_0, file_name, system_dir_0, import_proclib + lib_1 l_libs lib_name_1, file_name, system_dir_1, import_libimg + lib_2 l_libs lib_name_2, library_path, system_dir_2, import_buf2d + lib_3 l_libs lib_name_3, file_name, system_dir_3, import_box_lib +l_libs_end: + +align 4 +import_libimg: + dd alib_init1 + img_is_img dd aimg_is_img + img_info dd aimg_info + img_from_file dd aimg_from_file + img_to_file dd aimg_to_file + img_from_rgb dd aimg_from_rgb + img_to_rgb dd aimg_to_rgb + img_to_rgb2 dd aimg_to_rgb2 + img_decode dd aimg_decode + img_encode dd aimg_encode + img_create dd aimg_create + img_destroy dd aimg_destroy + img_destroy_layer dd aimg_destroy_layer + img_count dd aimg_count + img_lock_bits dd aimg_lock_bits + img_unlock_bits dd aimg_unlock_bits + img_flip dd aimg_flip + img_flip_layer dd aimg_flip_layer + img_rotate dd aimg_rotate + img_rotate_layer dd aimg_rotate_layer + img_draw dd aimg_draw + + dd 0,0 + alib_init1 db 'lib_init',0 + aimg_is_img db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение + aimg_info db 'img_info',0 + aimg_from_file db 'img_from_file',0 + aimg_to_file db 'img_to_file',0 + aimg_from_rgb db 'img_from_rgb',0 + aimg_to_rgb db 'img_to_rgb',0 ;преобразование изображения в данные RGB + aimg_to_rgb2 db 'img_to_rgb2',0 + aimg_decode db 'img_decode',0 ;автоматически определяет формат графических данных + aimg_encode db 'img_encode',0 + aimg_create db 'img_create',0 + aimg_destroy db 'img_destroy',0 + aimg_destroy_layer db 'img_destroy_layer',0 + aimg_count db 'img_count',0 + aimg_lock_bits db 'img_lock_bits',0 + aimg_unlock_bits db 'img_unlock_bits',0 + aimg_flip db 'img_flip',0 + aimg_flip_layer db 'img_flip_layer',0 + aimg_rotate db 'img_rotate',0 + aimg_rotate_layer db 'img_rotate_layer',0 + aimg_draw db 'img_draw',0 + +align 4 +import_proclib: + OpenDialog_Init dd aOpenDialog_Init + OpenDialog_Start dd aOpenDialog_Start + OpenDialog_Set_file_name dd aOpenDialog_Set_file_name + OpenDialog_Set_file_ext dd aOpenDialog_Set_file_ext +dd 0,0 + aOpenDialog_Init db 'OpenDialog_init',0 + aOpenDialog_Start db 'OpenDialog_start',0 + aOpenDialog_Set_file_name db 'OpenDialog_set_file_name',0 + aOpenDialog_Set_file_ext db 'OpenDialog_set_file_ext',0 + +align 4 +import_buf2d: + init dd sz_init + buf2d_create dd sz_buf2d_create + buf2d_create_f_img dd sz_buf2d_create_f_img + buf2d_clear dd sz_buf2d_clear + buf2d_draw dd sz_buf2d_draw + buf2d_delete dd sz_buf2d_delete + buf2d_resize dd sz_buf2d_resize + buf2d_line dd sz_buf2d_line + buf2d_line_sm dd sz_buf2d_line_sm + buf2d_rect_by_size dd sz_buf2d_rect_by_size + buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size + buf2d_circle dd sz_buf2d_circle + buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2 + buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2 + buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8 + buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32 + buf2d_bit_blt dd sz_buf2d_bit_blt + buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp + buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha + buf2d_curve_bezier dd sz_buf2d_curve_bezier + buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix + buf2d_draw_text dd sz_buf2d_draw_text + buf2d_crop_color dd sz_buf2d_crop_color + buf2d_flip_h dd sz_buf2d_flip_h + buf2d_flip_v dd sz_buf2d_flip_v + buf2d_offset_h dd sz_buf2d_offset_h + buf2d_flood_fill dd sz_buf2d_flood_fill + buf2d_set_pixel dd sz_buf2d_set_pixel + dd 0,0 + sz_init db 'lib_init',0 + sz_buf2d_create db 'buf2d_create',0 + sz_buf2d_create_f_img db 'buf2d_create_f_img',0 + sz_buf2d_clear db 'buf2d_clear',0 + sz_buf2d_draw db 'buf2d_draw',0 + sz_buf2d_delete db 'buf2d_delete',0 + sz_buf2d_resize db 'buf2d_resize',0 + sz_buf2d_line db 'buf2d_line',0 + sz_buf2d_line_sm db 'buf2d_line_sm',0 + sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0 + sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0 + sz_buf2d_circle db 'buf2d_circle',0 + sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0 + sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0 + sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0 + sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0 + sz_buf2d_bit_blt db 'buf2d_bit_blt',0 + sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0 + sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0 + sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0 + sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0 + sz_buf2d_draw_text db 'buf2d_draw_text',0 + sz_buf2d_crop_color db 'buf2d_crop_color',0 + sz_buf2d_flip_h db 'buf2d_flip_h',0 + sz_buf2d_flip_v db 'buf2d_flip_v',0 + sz_buf2d_offset_h db 'buf2d_offset_h',0 + sz_buf2d_flood_fill db 'buf2d_flood_fill',0 + sz_buf2d_set_pixel db 'buf2d_set_pixel',0 + +align 4 +import_box_lib: + dd sz_init1 + + init_checkbox dd sz_Init_checkbox + check_box_draw dd sz_Check_box_draw + check_box_mouse dd sz_Check_box_mouse + ;version_ch dd sz_Version_ch + + option_box_draw dd sz_Option_box_draw + option_box_mouse dd sz_Option_box_mouse + ;version_op dd sz_Version_op + + edit_box_draw dd sz_edit_box_draw + edit_box_key dd sz_edit_box_key + edit_box_mouse dd sz_edit_box_mouse + edit_box_set_text dd sz_edit_box_set_text + scrollbar_ver_draw dd sz_scrollbar_ver_draw + scrollbar_hor_draw dd sz_scrollbar_hor_draw + + tl_data_init dd sz_tl_data_init + tl_data_clear dd sz_tl_data_clear + tl_info_clear dd sz_tl_info_clear + tl_key dd sz_tl_key + tl_mouse dd sz_tl_mouse + tl_draw dd sz_tl_draw + tl_info_undo dd sz_tl_info_undo + tl_info_redo dd sz_tl_info_redo + tl_node_add dd sz_tl_node_add + tl_node_set_data dd sz_tl_node_set_data + tl_node_get_data dd sz_tl_node_get_data + tl_node_delete dd sz_tl_node_delete + tl_node_move_up dd sz_tl_node_move_up + tl_node_move_down dd sz_tl_node_move_down + tl_cur_beg dd sz_tl_cur_beg + tl_cur_next dd sz_tl_cur_next + tl_cur_perv dd sz_tl_cur_perv + tl_node_close_open dd sz_tl_node_close_open + tl_node_lev_inc dd sz_tl_node_lev_inc + tl_node_lev_dec dd sz_tl_node_lev_dec + tl_node_poi_get_info dd sz_tl_node_poi_get_info + tl_node_poi_get_next_info dd sz_tl_node_poi_get_next_info + tl_node_poi_get_data dd sz_tl_node_poi_get_data + + dd 0,0 + sz_init1 db 'lib_init',0 + + sz_Init_checkbox db 'init_checkbox2',0 + sz_Check_box_draw db 'check_box_draw2',0 + sz_Check_box_mouse db 'check_box_mouse2',0 + ;sz_Version_ch db 'version_ch2',0 + + sz_Option_box_draw db 'option_box_draw',0 + sz_Option_box_mouse db 'option_box_mouse',0 + ;sz_Version_op db 'version_op',0 + + sz_edit_box_draw db 'edit_box_draw',0 + sz_edit_box_key db 'edit_box_key',0 + sz_edit_box_mouse db 'edit_box_mouse',0 + sz_edit_box_set_text db 'edit_box_set_text',0 + sz_scrollbar_ver_draw db 'scrollbar_v_draw',0 + sz_scrollbar_hor_draw db 'scrollbar_h_draw',0 + + sz_tl_data_init db 'tl_data_init',0 + sz_tl_data_clear db 'tl_data_clear',0 + sz_tl_info_clear db 'tl_info_clear',0 + sz_tl_key db 'tl_key',0 + sz_tl_mouse db 'tl_mouse',0 + sz_tl_draw db 'tl_draw',0 + sz_tl_info_undo db 'tl_info_undo',0 + sz_tl_info_redo db 'tl_info_redo',0 + sz_tl_node_add db 'tl_node_add',0 + sz_tl_node_set_data db 'tl_node_set_data',0 + sz_tl_node_get_data db 'tl_node_get_data',0 + sz_tl_node_delete db 'tl_node_delete',0 + sz_tl_node_move_up db 'tl_node_move_up',0 + sz_tl_node_move_down db 'tl_node_move_down',0 + sz_tl_cur_beg db 'tl_cur_beg',0 + sz_tl_cur_next db 'tl_cur_next',0 + sz_tl_cur_perv db 'tl_cur_perv',0 + sz_tl_node_close_open db 'tl_node_close_open',0 + sz_tl_node_lev_inc db 'tl_node_lev_inc',0 + sz_tl_node_lev_dec db 'tl_node_lev_dec',0 + sz_tl_node_poi_get_info db 'tl_node_poi_get_info',0 + sz_tl_node_poi_get_next_info db 'tl_node_poi_get_next_info',0 + sz_tl_node_poi_get_data db 'tl_node_poi_get_data',0 + +align 4 +mouse_dd dd 0 +last_time dd 0 + +align 16 +sc system_colors + +align 16 +procinfo process_information + +align 4 +buf_0: dd 0 ;указатель на буфер изображения +.l: dw 205 ;+4 left +.t: dw 35 ;+6 top +.w: dd 384 ;+8 w +.h: dd 350 ;+12 h +.color: dd 0xffffd0 ;+16 color + db 24 ;+20 bit in pixel + +align 4 +buf_1: + dd 0 ;указатель на буфер изображения + dd 0 ;+4 left,top +.w: dd 0 +.h: dd 0,0,24 ;+12 color,bit in pixel + +font_h dd 0 ;высота шрифта + +align 4 +buf_png: + dd 0,0 +.w: dd 0 +.h: dd 0,0xffffff,24 + +align 4 +el_focus dd tree1 +tree1 tree_list size_one_list,1000+2, tl_key_no_edit+tl_draw_par_line,\ + 16,16, 0xffffff,0xb0d0ff,0x400040, 5,35,195-16,340, 16,Figure.Caption,0,\ + el_focus,w_scr_t1,0 + +align 4 +w_scr_t1 scrollbar 16,0, 3,0, 15, 100, 0,0, 0,0,0, 1 + +;input: +; eax - число +; edi - буфер для строки +; len - длинна буфера +;output: +align 4 +proc convert_int_to_str uses eax ecx edx edi esi, len:dword + mov esi,[len] + add esi,edi + dec esi + call .str + ret +endp + +align 4 +.str: + mov ecx,10 + cmp eax,ecx + jb @f + xor edx,edx + div ecx + push edx + ;dec edi ;смещение необходимое для записи с конца строки + call .str + pop eax + @@: + cmp edi,esi + jge @f + or al,0x30 + stosb + mov byte[edi],0 ;в конец строки ставим 0, что-бы не вылазил мусор + @@: + ret + +align 4 +proc mem_copy uses ecx esi edi, destination:dword, source:dword, len:dword + cld + mov esi, dword[source] + mov edi, dword[destination] + mov ecx, dword[len] + rep movsb + ret +endp + +align 16 +i_end: + rb 2048 +thread_coords: + rb 2048 +thread_scale: + rb 2048 +thread_n_file: + rb 2048 +stacktop: + sys_path rb 1024 + file_name: + rb 1024 ;4096 + library_path rb 1024 + plugin_path rb 4096 + openfile_path rb 4096 + filename_area rb 256 +mem: