Ver 1.0
This commit is contained in:
156
FasmDll/DEMO/ASMDEMO.ASM
Normal file
156
FasmDll/DEMO/ASMDEMO.ASM
Normal file
@@ -0,0 +1,156 @@
|
||||
|
||||
format PE GUI 4.0
|
||||
entry start
|
||||
|
||||
include 'win32a.inc'
|
||||
include 'fasm.ash'
|
||||
include 'fedit.ash'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
_fedit db 'FEDIT.DLL',0
|
||||
_caption db 'flat assembler %d.%d',0
|
||||
_error db 'ERROR',0
|
||||
|
||||
_source db 0Dh,0Ah
|
||||
db ' org 100h',0Dh,0Ah
|
||||
db 0Dh,0Ah
|
||||
db ' mov ah,09h ',' ; write',0Dh,0Ah
|
||||
db ' mov dx,text',0Dh,0Ah
|
||||
db ' int 21h',0Dh,0Ah
|
||||
db ' int 20h',0Dh,0Ah
|
||||
db 0Dh,0Ah
|
||||
db ' text db "Hello!",24h',0Dh,0Ah
|
||||
db 0
|
||||
|
||||
buffer rb 10000h
|
||||
|
||||
fasm_memory:
|
||||
fasm_state FASM_STATE
|
||||
rb 800000h-($-fasm_memory) ; reserve total 8 MB for assembler
|
||||
|
||||
section '.code' code readable executable
|
||||
|
||||
start:
|
||||
|
||||
invoke LoadLibrary,_fedit
|
||||
or eax,eax
|
||||
jz exit
|
||||
invoke GetModuleHandle,0
|
||||
invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
|
||||
|
||||
exit:
|
||||
invoke ExitProcess,0
|
||||
|
||||
proc DialogProc hwnddlg,msg,wparam,lparam
|
||||
push ebx esi edi
|
||||
cmp [msg],WM_INITDIALOG
|
||||
je wminitdialog
|
||||
cmp [msg],WM_COMMAND
|
||||
je wmcommand
|
||||
cmp [msg],WM_CLOSE
|
||||
je wmclose
|
||||
xor eax,eax
|
||||
jmp finish
|
||||
wminitdialog:
|
||||
invoke fasm_GetVersion
|
||||
mov edx,eax
|
||||
and eax,0FFFFh
|
||||
shr edx,16
|
||||
cinvoke wsprintf,buffer,_caption,eax,edx
|
||||
invoke SendMessage,[hwnddlg],WM_SETTEXT,0,buffer
|
||||
invoke SetDlgItemText,[hwnddlg],ID_SOURCE,_source
|
||||
jmp processed
|
||||
wmcommand:
|
||||
cmp [wparam],BN_CLICKED shl 16 + IDCANCEL
|
||||
je wmclose
|
||||
cmp [wparam],BN_CLICKED shl 16 + IDOK
|
||||
jne processed
|
||||
|
||||
invoke GetDlgItemText,[hwnddlg],ID_SOURCE,buffer,10000h
|
||||
|
||||
invoke fasm_Assemble,buffer,fasm_memory,800000h,100,NULL
|
||||
cmp eax,FASM_OK
|
||||
je show_output
|
||||
|
||||
invoke SetDlgItemText,[hwnddlg],ID_OUTPUT,_error
|
||||
|
||||
jmp processed
|
||||
|
||||
show_output:
|
||||
|
||||
mov esi,[fasm_state.output_data]
|
||||
mov ecx,[fasm_state.output_length]
|
||||
mov edi,buffer
|
||||
xor edx,edx
|
||||
jecxz output_ok
|
||||
output_to_hex:
|
||||
test dl,7
|
||||
jz @f
|
||||
mov al,20h
|
||||
stosb
|
||||
@@:
|
||||
mov al,[esi+edx]
|
||||
shr al,4
|
||||
cmp al,10
|
||||
sbb al,69h
|
||||
das
|
||||
stosb
|
||||
mov al,[esi+edx]
|
||||
and al,0Fh
|
||||
cmp al,10
|
||||
sbb al,69h
|
||||
das
|
||||
stosb
|
||||
inc edx
|
||||
test dl,7
|
||||
jnz @f
|
||||
mov ax,0D0Ah
|
||||
stosw
|
||||
@@:
|
||||
loop output_to_hex
|
||||
output_ok:
|
||||
xor al,al
|
||||
stosb
|
||||
|
||||
invoke SetDlgItemText,[hwnddlg],ID_OUTPUT,buffer
|
||||
|
||||
jmp processed
|
||||
wmclose:
|
||||
invoke EndDialog,[hwnddlg],0
|
||||
processed:
|
||||
mov eax,1
|
||||
finish:
|
||||
pop edi esi ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel32,'KERNEL32.DLL',\
|
||||
user32,'USER32.DLL',\
|
||||
fasm,'FASM.DLL'
|
||||
|
||||
include 'api\kernel32.inc'
|
||||
include 'api\user32.inc'
|
||||
|
||||
import fasm,\
|
||||
fasm_GetVersion,'fasm_GetVersion',\
|
||||
fasm_Assemble,'fasm_Assemble',\
|
||||
fasm_AssembleFile,'fasm_AssembleFile'
|
||||
|
||||
section '.rsrc' resource data readable
|
||||
|
||||
ID_SOURCE = 100
|
||||
ID_OUTPUT = 101
|
||||
|
||||
directory RT_DIALOG,dialogs
|
||||
|
||||
resource dialogs,\
|
||||
37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration
|
||||
|
||||
dialog demonstration,'Memory-to-memory assembly',40,40,180,220,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
|
||||
dialogitem 'FEDIT','',ID_SOURCE,10,10,160,120,WS_VISIBLE+WS_BORDER+WS_TABSTOP
|
||||
dialogitem 'FEDIT','',ID_OUTPUT,10,150,160,60,WS_VISIBLE+WS_BORDER+WS_TABSTOP
|
||||
dialogitem 'BUTTON','Assemble',IDOK,10,132,160,15,WS_VISIBLE+WS_TABSTOP
|
||||
enddialog
|
||||
104
FasmDll/DEMO/FASM.ASH
Normal file
104
FasmDll/DEMO/FASM.ASH
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
; The following structure resides at the beginning of memory block provided
|
||||
; to the fasm_Assemble function. The condition field contains the same value
|
||||
; as the one returned by function.
|
||||
; When function returns FASM_OK condition, the output_length and
|
||||
; output_data fields are filled - with pointer to generated output
|
||||
; (somewhere within the provided memory block) and the count of bytes stored
|
||||
; there.
|
||||
; When function returns FASM_ERROR, the error_code is filled with the
|
||||
; code of specific error that happened and error_line is a pointer to the
|
||||
; LINE_HEADER structure, providing information about the line that caused
|
||||
; the error.
|
||||
|
||||
struct FASM_STATE
|
||||
condition dd ?
|
||||
union
|
||||
output_length dd ?
|
||||
error_code dd ?
|
||||
ends
|
||||
union
|
||||
output_data dd ?
|
||||
error_line dd ?
|
||||
ends
|
||||
ends
|
||||
|
||||
; The following structure has two variants - it either defines the line
|
||||
; that was loaded directly from source, or the line that was generated by
|
||||
; macroinstruction. First case has the highest bit of line_number set to 0,
|
||||
; while the second case has this bit set.
|
||||
; In the first case, the file_path field contains pointer to the path of
|
||||
; source file (empty string if it's the source that was provided directly to
|
||||
; fasm_Assemble function), the line_number is the number of line within
|
||||
; that file (starting from 1) and the file_offset field contains the offset
|
||||
; within the file where the line starts.
|
||||
; In the second case the macro_calling_line field contains the pointer to
|
||||
; LINE_HEADER structure for the line which called the macroinstruction, and
|
||||
; the macro_line field contains the pointer to LINE_HEADER structure for the
|
||||
; line within the definition of macroinstruction, which generated this one.
|
||||
|
||||
struct LINE_HEADER
|
||||
file_path dd ?
|
||||
line_number dd ?
|
||||
union
|
||||
file_offset dd ?
|
||||
macro_calling_line dd ?
|
||||
ends
|
||||
macro_line dd ?
|
||||
ends
|
||||
|
||||
; General errors and conditions
|
||||
|
||||
FASM_OK = 0 ; FASM_STATE points to output
|
||||
FASM_WORKING = 1
|
||||
FASM_ERROR = 2 ; FASM_STATE contains error code
|
||||
FASM_INVALID_PARAMETER = -1
|
||||
FASM_OUT_OF_MEMORY = -2
|
||||
FASM_STACK_OVERFLOW = -3
|
||||
FASM_SOURCE_NOT_FOUND = -4
|
||||
FASM_UNEXPECTED_END_OF_SOURCE = -5
|
||||
FASM_CANNOT_GENERATE_CODE = -6
|
||||
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
|
||||
FASM_WRITE_FAILED = -8
|
||||
FASM_INVALID_DEFINITION = -9
|
||||
|
||||
; Error codes for FASM_ERROR condition
|
||||
|
||||
FASMERR_FILE_NOT_FOUND = -101
|
||||
FASMERR_ERROR_READING_FILE = -102
|
||||
FASMERR_INVALID_FILE_FORMAT = -103
|
||||
FASMERR_INVALID_MACRO_ARGUMENTS = -104
|
||||
FASMERR_INCOMPLETE_MACRO = -105
|
||||
FASMERR_UNEXPECTED_CHARACTERS = -106
|
||||
FASMERR_INVALID_ARGUMENT = -107
|
||||
FASMERR_ILLEGAL_INSTRUCTION = -108
|
||||
FASMERR_INVALID_OPERAND = -109
|
||||
FASMERR_INVALID_OPERAND_SIZE = -110
|
||||
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
|
||||
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
|
||||
FASMERR_INVALID_ADDRESS_SIZE = -113
|
||||
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
|
||||
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
|
||||
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
|
||||
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
|
||||
FASMERR_INVALID_EXPRESSION = -118
|
||||
FASMERR_INVALID_ADDRESS = -119
|
||||
FASMERR_INVALID_VALUE = -120
|
||||
FASMERR_VALUE_OUT_OF_RANGE = -121
|
||||
FASMERR_UNDEFINED_SYMBOL = -122
|
||||
FASMERR_INVALID_USE_OF_SYMBOL = -123
|
||||
FASMERR_NAME_TOO_LONG = -124
|
||||
FASMERR_INVALID_NAME = -125
|
||||
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
|
||||
FASMERR_SYMBOL_ALREADY_DEFINED = -127
|
||||
FASMERR_MISSING_END_QUOTE = -128
|
||||
FASMERR_MISSING_END_DIRECTIVE = -129
|
||||
FASMERR_UNEXPECTED_INSTRUCTION = -130
|
||||
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
|
||||
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
|
||||
FASMERR_SETTING_ALREADY_SPECIFIED = -133
|
||||
FASMERR_DATA_ALREADY_DEFINED = -134
|
||||
FASMERR_TOO_MANY_REPEATS = -135
|
||||
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
|
||||
FASMERR_USER_ERROR = -140
|
||||
FASMERR_ASSERTION_FAILED = -141
|
||||
69
FasmDll/DEMO/FEDIT.ASH
Normal file
69
FasmDll/DEMO/FEDIT.ASH
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
; flat editor mode flags
|
||||
|
||||
FEMODE_OVERWRITE = 1
|
||||
FEMODE_VERTICALSEL = 2
|
||||
FEMODE_NOUNDO = 4
|
||||
FEMODE_READONLY = 8
|
||||
|
||||
; flat editor search flags
|
||||
|
||||
FEFIND_CASESENSITIVE = 1
|
||||
FEFIND_WHOLEWORDS = 2
|
||||
FEFIND_BACKWARD = 4
|
||||
FEFIND_INWHOLETEXT = 8
|
||||
|
||||
; flat editor styles
|
||||
|
||||
FES_AUTOINDENT = 0001h
|
||||
FES_AUTOBRACKETS = 0002h
|
||||
FES_SMARTTABS = 0004h
|
||||
FES_SECURESEL = 0008h
|
||||
FES_OPTIMALFILL = 0010h
|
||||
FES_CONSOLECARET = 0020h
|
||||
FES_REVIVEDEADKEYS = 0040h
|
||||
FES_TIMESCROLL = 0080h
|
||||
|
||||
; flat editor messages
|
||||
|
||||
FEM_SETMODE = WM_USER + 0
|
||||
FEM_GETMODE = WM_USER + 1
|
||||
FEM_SETPOS = WM_USER + 2
|
||||
FEM_GETPOS = WM_USER + 3
|
||||
FEM_SETSYNTAXHIGHLIGHT = WM_USER + 4
|
||||
FEM_SETRIGHTCLICKMENU = WM_USER + 5
|
||||
FEM_SETTEXTCOLOR = WM_USER + 6
|
||||
FEM_SETSELCOLOR = WM_USER + 7
|
||||
FEM_FINDFIRST = WM_USER + 8
|
||||
FEM_FINDNEXT = WM_USER + 9
|
||||
FEM_CANFINDNEXT = WM_USER + 10
|
||||
FEM_GETLINELENGTH = WM_USER + 11
|
||||
FEM_GETLINE = WM_USER + 12
|
||||
FEM_GETWORDATCARET = WM_USER + 13
|
||||
FEM_BEGINOPERATION = WM_USER + 14
|
||||
FEM_ENDOPERATION = WM_USER + 15
|
||||
FEM_MARKUNMODIFIED = WM_USER + 16
|
||||
FEM_ISUNMODIFIED = WM_USER + 17
|
||||
FEM_GETSEARCHTEXT = WM_USER + 18
|
||||
FEM_GETSEARCHFLAGS = WM_USER + 19
|
||||
FEM_RELEASESEARCH = WM_USER + 20
|
||||
FEM_REDO = WM_USER + 84
|
||||
FEM_CANREDO = WM_USER + 85
|
||||
|
||||
; flat editor notifications
|
||||
|
||||
FEN_SETFOCUS = 01h
|
||||
FEN_KILLFOCUS = 02h
|
||||
FEN_TEXTCHANGE = 03h
|
||||
FEN_POSCHANGE = 04h
|
||||
FEN_MODECHANGE = 05h
|
||||
FEN_OUTOFMEMORY = 0Fh
|
||||
|
||||
; flat editor position structure
|
||||
|
||||
struct FEPOS
|
||||
selectionPosition dd ?
|
||||
selectionLine dd ?
|
||||
caretPosition dd ?
|
||||
caretLine dd ?
|
||||
ends
|
||||
104
FasmDll/FASM.ASH
Normal file
104
FasmDll/FASM.ASH
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
; The following structure resides at the beginning of memory block provided
|
||||
; to the fasm_Assemble function. The condition field contains the same value
|
||||
; as the one returned by function.
|
||||
; When function returns FASM_OK condition, the output_length and
|
||||
; output_data fields are filled - with pointer to generated output
|
||||
; (somewhere within the provided memory block) and the count of bytes stored
|
||||
; there.
|
||||
; When function returns FASM_ERROR, the error_code is filled with the
|
||||
; code of specific error that happened and error_line is a pointer to the
|
||||
; LINE_HEADER structure, providing information about the line that caused
|
||||
; the error.
|
||||
|
||||
struct FASM_STATE
|
||||
condition dd ?
|
||||
union
|
||||
output_length dd ?
|
||||
error_code dd ?
|
||||
ends
|
||||
union
|
||||
output_data dd ?
|
||||
error_line dd ?
|
||||
ends
|
||||
ends
|
||||
|
||||
; The following structure has two variants - it either defines the line
|
||||
; that was loaded directly from source, or the line that was generated by
|
||||
; macroinstruction. First case has the highest bit of line_number set to 0,
|
||||
; while the second case has this bit set.
|
||||
; In the first case, the file_path field contains pointer to the path of
|
||||
; source file (empty string if it's the source that was provided directly to
|
||||
; fasm_Assemble function), the line_number is the number of line within
|
||||
; that file (starting from 1) and the file_offset field contains the offset
|
||||
; within the file where the line starts.
|
||||
; In the second case the macro_calling_line field contains the pointer to
|
||||
; LINE_HEADER structure for the line which called the macroinstruction, and
|
||||
; the macro_line field contains the pointer to LINE_HEADER structure for the
|
||||
; line within the definition of macroinstruction, which generated this one.
|
||||
|
||||
struct LINE_HEADER
|
||||
file_path dd ?
|
||||
line_number dd ?
|
||||
union
|
||||
file_offset dd ?
|
||||
macro_calling_line dd ?
|
||||
ends
|
||||
macro_line dd ?
|
||||
ends
|
||||
|
||||
; General errors and conditions
|
||||
|
||||
FASM_OK = 0 ; FASM_STATE points to output
|
||||
FASM_WORKING = 1
|
||||
FASM_ERROR = 2 ; FASM_STATE contains error code
|
||||
FASM_INVALID_PARAMETER = -1
|
||||
FASM_OUT_OF_MEMORY = -2
|
||||
FASM_STACK_OVERFLOW = -3
|
||||
FASM_SOURCE_NOT_FOUND = -4
|
||||
FASM_UNEXPECTED_END_OF_SOURCE = -5
|
||||
FASM_CANNOT_GENERATE_CODE = -6
|
||||
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
|
||||
FASM_WRITE_FAILED = -8
|
||||
FASM_INVALID_DEFINITION = -9
|
||||
|
||||
; Error codes for FASM_ERROR condition
|
||||
|
||||
FASMERR_FILE_NOT_FOUND = -101
|
||||
FASMERR_ERROR_READING_FILE = -102
|
||||
FASMERR_INVALID_FILE_FORMAT = -103
|
||||
FASMERR_INVALID_MACRO_ARGUMENTS = -104
|
||||
FASMERR_INCOMPLETE_MACRO = -105
|
||||
FASMERR_UNEXPECTED_CHARACTERS = -106
|
||||
FASMERR_INVALID_ARGUMENT = -107
|
||||
FASMERR_ILLEGAL_INSTRUCTION = -108
|
||||
FASMERR_INVALID_OPERAND = -109
|
||||
FASMERR_INVALID_OPERAND_SIZE = -110
|
||||
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
|
||||
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
|
||||
FASMERR_INVALID_ADDRESS_SIZE = -113
|
||||
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
|
||||
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
|
||||
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
|
||||
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
|
||||
FASMERR_INVALID_EXPRESSION = -118
|
||||
FASMERR_INVALID_ADDRESS = -119
|
||||
FASMERR_INVALID_VALUE = -120
|
||||
FASMERR_VALUE_OUT_OF_RANGE = -121
|
||||
FASMERR_UNDEFINED_SYMBOL = -122
|
||||
FASMERR_INVALID_USE_OF_SYMBOL = -123
|
||||
FASMERR_NAME_TOO_LONG = -124
|
||||
FASMERR_INVALID_NAME = -125
|
||||
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
|
||||
FASMERR_SYMBOL_ALREADY_DEFINED = -127
|
||||
FASMERR_MISSING_END_QUOTE = -128
|
||||
FASMERR_MISSING_END_DIRECTIVE = -129
|
||||
FASMERR_UNEXPECTED_INSTRUCTION = -130
|
||||
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
|
||||
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
|
||||
FASMERR_SETTING_ALREADY_SPECIFIED = -133
|
||||
FASMERR_DATA_ALREADY_DEFINED = -134
|
||||
FASMERR_TOO_MANY_REPEATS = -135
|
||||
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
|
||||
FASMERR_USER_ERROR = -140
|
||||
FASMERR_ASSERTION_FAILED = -141
|
||||
49
FasmDll/FASMDLL.TXT
Normal file
49
FasmDll/FASMDLL.TXT
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
Short description of functions inside FASM.DLL
|
||||
|
||||
|
||||
fasm_GetVersion()
|
||||
|
||||
Returns double word containg major version in lower 16 bits,
|
||||
and minor version in the higher 16 bits.
|
||||
|
||||
fasm_Assemble(lpSource,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
|
||||
|
||||
Assembles the given source, using the provided memory block as a free
|
||||
storage space (which is also to contain generated output).
|
||||
|
||||
The lpSource should contain a pointer to zero-ended source text.
|
||||
|
||||
The lpMemory should be a pointer to the memory block and cbMemorySize
|
||||
should contain its size. In the beginning of this memory block the
|
||||
FASM_STATE structure will reside (as defined in FASM.ASH). The assembler
|
||||
doesn't allocate any memory beside this block, if it is not enough for
|
||||
its purposes, the function returns with FASM_OUT_OF_MEMORY state.
|
||||
|
||||
The nPassesLimit should be a value in range from 1 to 65536, defining
|
||||
the maximum number of passes the assembler can perform in order to
|
||||
generate the code (the recommended value is 100). If the limit is reached,
|
||||
the function returns with state FASM_CANNOT_GENERATE_CODE.
|
||||
|
||||
The hDisplayPipe should contain handle of the pipe, to which the output
|
||||
of DISPLAY directives will be written. If this parameter is NULL, all
|
||||
the display will get discarded.
|
||||
|
||||
If the assembly is successful, function returns FASM_OK value and fills
|
||||
the output_data and output_length fields of the FASM_STATE structure
|
||||
(which resides at the beginning of provided memory block) with pointer
|
||||
to the generated output and count of bytes stored there.
|
||||
|
||||
If the assembly failed, function returns one of the other general
|
||||
conditions as defined in FASM.ASH. If the condition returned is FASM_ERROR,
|
||||
it means that an error caused by a specific place in source occured,
|
||||
then the error_code and error_line fields of FASM_STATE are filled,
|
||||
first one with detailed error code as defined in FASM.ASH, and the second
|
||||
one with pointer to a structure containing data about line that caused
|
||||
the error.
|
||||
|
||||
fasm_AssembleFile(lpSourceFile,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
|
||||
|
||||
This function performs identically to fasm_Assemble, except that it takes
|
||||
the lpSourceFile parameter in place of lpSource, and it shall contain the
|
||||
pointer to zero-ended path to file containing the source to assemble.
|
||||
37
FasmDll/LICENSE.TXT
Normal file
37
FasmDll/LICENSE.TXT
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
flat assembler version 1.71
|
||||
Copyright (c) 1999-2014, Tomasz Grysztar.
|
||||
All rights reserved.
|
||||
|
||||
This program is free for commercial and non-commercial use as long as
|
||||
the following conditions are adhered to.
|
||||
|
||||
Copyright remains Tomasz Grysztar, and as such any Copyright notices
|
||||
in the code are not to be removed.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The licence and distribution terms for any publically available
|
||||
version or derivative of this code cannot be changed. i.e. this code
|
||||
cannot simply be copied and put under another distribution licence
|
||||
(including the GNU Public Licence).
|
||||
147
FasmDll/SOURCE/DLL/ERRORS.INC
Normal file
147
FasmDll/SOURCE/DLL/ERRORS.INC
Normal file
@@ -0,0 +1,147 @@
|
||||
|
||||
; flat assembler core
|
||||
; Copyright (c) 1999-2017, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
invalid_parameter:
|
||||
mov eax,FASM_INVALID_PARAMETER
|
||||
jmp general_error
|
||||
out_of_memory:
|
||||
mov eax,FASM_OUT_OF_MEMORY
|
||||
jmp general_error
|
||||
stack_overflow:
|
||||
mov eax,FASM_STACK_OVERFLOW
|
||||
jmp general_error
|
||||
main_file_not_found:
|
||||
mov eax,FASM_SOURCE_NOT_FOUND
|
||||
jmp general_error
|
||||
unexpected_end_of_file:
|
||||
mov eax,FASM_UNEXPECTED_END_OF_SOURCE
|
||||
jmp general_error
|
||||
code_cannot_be_generated:
|
||||
mov eax,FASM_CANNOT_GENERATE_CODE
|
||||
jmp general_error
|
||||
format_limitations_exceeded:
|
||||
mov eax,FASM_FORMAT_LIMITATIONS_EXCEDDED
|
||||
jmp general_error
|
||||
invalid_definition:
|
||||
mov eax,FASM_INVALID_DEFINITION
|
||||
jmp general_error
|
||||
write_failed:
|
||||
mov eax,FASM_WRITE_FAILED
|
||||
jmp general_error
|
||||
|
||||
file_not_found:
|
||||
mov eax,FASMERR_FILE_NOT_FOUND
|
||||
jmp assembler_error
|
||||
error_reading_file:
|
||||
mov eax,FASMERR_ERROR_READING_FILE
|
||||
jmp assembler_error
|
||||
invalid_file_format:
|
||||
mov eax,FASMERR_INVALID_FILE_FORMAT
|
||||
jmp assembler_error
|
||||
invalid_macro_arguments:
|
||||
mov eax,FASMERR_INVALID_MACRO_ARGUMENTS
|
||||
jmp assembler_error
|
||||
incomplete_macro:
|
||||
mov eax,FASMERR_INCOMPLETE_MACRO
|
||||
jmp assembler_error
|
||||
unexpected_characters:
|
||||
mov eax,FASMERR_UNEXPECTED_CHARACTERS
|
||||
jmp assembler_error
|
||||
invalid_argument:
|
||||
mov eax,FASMERR_INVALID_ARGUMENT
|
||||
jmp assembler_error
|
||||
illegal_instruction:
|
||||
mov eax,FASMERR_ILLEGAL_INSTRUCTION
|
||||
jmp assembler_error
|
||||
invalid_operand:
|
||||
mov eax,FASMERR_INVALID_OPERAND
|
||||
jmp assembler_error
|
||||
invalid_operand_size:
|
||||
mov eax,FASMERR_INVALID_OPERAND_SIZE
|
||||
jmp assembler_error
|
||||
operand_size_not_specified:
|
||||
mov eax,FASMERR_OPERAND_SIZE_NOT_SPECIFIED
|
||||
jmp assembler_error
|
||||
operand_sizes_do_not_match:
|
||||
mov eax,FASMERR_OPERAND_SIZES_DO_NOT_MATCH
|
||||
jmp assembler_error
|
||||
invalid_address_size:
|
||||
mov eax,FASMERR_INVALID_ADDRESS_SIZE
|
||||
jmp assembler_error
|
||||
address_sizes_do_not_agree:
|
||||
mov eax,FASMERR_ADDRESS_SIZES_DO_NOT_AGREE
|
||||
jmp assembler_error
|
||||
disallowed_combination_of_registers:
|
||||
mov eax,FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS
|
||||
jmp assembler_error
|
||||
long_immediate_not_encodable:
|
||||
mov eax,FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE
|
||||
jmp assembler_error
|
||||
relative_jump_out_of_range:
|
||||
mov eax,FASMERR_RELATIVE_JUMP_OUT_OF_RANGE
|
||||
jmp assembler_error
|
||||
invalid_expression:
|
||||
mov eax,FASMERR_INVALID_EXPRESSION
|
||||
jmp assembler_error
|
||||
invalid_address:
|
||||
mov eax,FASMERR_INVALID_ADDRESS
|
||||
jmp assembler_error
|
||||
invalid_value:
|
||||
mov eax,FASMERR_INVALID_VALUE
|
||||
jmp assembler_error
|
||||
value_out_of_range:
|
||||
mov eax,FASMERR_VALUE_OUT_OF_RANGE
|
||||
jmp assembler_error
|
||||
undefined_symbol:
|
||||
mov eax,FASMERR_UNDEFINED_SYMBOL
|
||||
jmp assembler_error
|
||||
invalid_use_of_symbol:
|
||||
mov eax,FASMERR_INVALID_USE_OF_SYMBOL
|
||||
jmp assembler_error
|
||||
name_too_long:
|
||||
mov eax,FASMERR_NAME_TOO_LONG
|
||||
jmp assembler_error
|
||||
invalid_name:
|
||||
mov eax,FASMERR_INVALID_NAME
|
||||
jmp assembler_error
|
||||
reserved_word_used_as_symbol:
|
||||
mov eax,FASMERR_RESERVED_WORD_USED_AS_SYMBOL
|
||||
jmp assembler_error
|
||||
symbol_already_defined:
|
||||
mov eax,FASMERR_SYMBOL_ALREADY_DEFINED
|
||||
jmp assembler_error
|
||||
symbol_out_of_scope:
|
||||
mov eax,FASMERR_SYMBOL_OUT_OF_SCOPE
|
||||
jmp assembler_error
|
||||
missing_end_quote:
|
||||
mov eax,FASMERR_MISSING_END_QUOTE
|
||||
jmp assembler_error
|
||||
missing_end_directive:
|
||||
mov eax,FASMERR_MISSING_END_DIRECTIVE
|
||||
jmp assembler_error
|
||||
unexpected_instruction:
|
||||
mov eax,FASMERR_UNEXPECTED_INSTRUCTION
|
||||
jmp assembler_error
|
||||
extra_characters_on_line:
|
||||
mov eax,FASMERR_EXTRA_CHARACTERS_ON_LINE
|
||||
jmp assembler_error
|
||||
section_not_aligned_enough:
|
||||
mov eax,FASMERR_SECTION_NOT_ALIGNED_ENOUGH
|
||||
jmp assembler_error
|
||||
setting_already_specified:
|
||||
mov eax,FASMERR_SETTING_ALREADY_SPECIFIED
|
||||
jmp assembler_error
|
||||
data_already_defined:
|
||||
mov eax,FASMERR_DATA_ALREADY_DEFINED
|
||||
jmp assembler_error
|
||||
too_many_repeats:
|
||||
mov eax,FASMERR_TOO_MANY_REPEATS
|
||||
jmp assembler_error
|
||||
invoked_error:
|
||||
mov eax,FASMERR_USER_ERROR
|
||||
jmp assembler_error
|
||||
assertion_failed:
|
||||
mov eax,FASMERR_ASSERTION_FAILED
|
||||
jmp assembler_error
|
||||
104
FasmDll/SOURCE/DLL/FASM.ASH
Normal file
104
FasmDll/SOURCE/DLL/FASM.ASH
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
; The following structure resides at the beginning of memory block provided
|
||||
; to the fasm_Assemble function. The condition field contains the same value
|
||||
; as the one returned by function.
|
||||
; When function returns FASM_OK condition, the output_length and
|
||||
; output_data fields are filled - with pointer to generated output
|
||||
; (somewhere within the provided memory block) and the count of bytes stored
|
||||
; there.
|
||||
; When function returns FASM_ERROR, the error_code is filled with the
|
||||
; code of specific error that happened and error_line is a pointer to the
|
||||
; LINE_HEADER structure, providing information about the line that caused
|
||||
; the error.
|
||||
|
||||
struct FASM_STATE
|
||||
condition dd ?
|
||||
union
|
||||
output_length dd ?
|
||||
error_code dd ?
|
||||
ends
|
||||
union
|
||||
output_data dd ?
|
||||
error_line dd ?
|
||||
ends
|
||||
ends
|
||||
|
||||
; The following structure has two variants - it either defines the line
|
||||
; that was loaded directly from source, or the line that was generated by
|
||||
; macroinstruction. First case has the highest bit of line_number set to 0,
|
||||
; while the second case has this bit set.
|
||||
; In the first case, the file_path field contains pointer to the path of
|
||||
; source file (empty string if it's the source that was provided directly to
|
||||
; fasm_Assemble function), the line_number is the number of line within
|
||||
; that file (starting from 1) and the file_offset field contains the offset
|
||||
; within the file where the line starts.
|
||||
; In the second case the macro_calling_line field contains the pointer to
|
||||
; LINE_HEADER structure for the line which called the macroinstruction, and
|
||||
; the macro_line field contains the pointer to LINE_HEADER structure for the
|
||||
; line within the definition of macroinstruction, which generated this one.
|
||||
|
||||
struct LINE_HEADER
|
||||
file_path dd ?
|
||||
line_number dd ?
|
||||
union
|
||||
file_offset dd ?
|
||||
macro_calling_line dd ?
|
||||
ends
|
||||
macro_line dd ?
|
||||
ends
|
||||
|
||||
; General errors and conditions
|
||||
|
||||
FASM_OK = 0 ; FASM_STATE points to output
|
||||
FASM_WORKING = 1
|
||||
FASM_ERROR = 2 ; FASM_STATE contains error code
|
||||
FASM_INVALID_PARAMETER = -1
|
||||
FASM_OUT_OF_MEMORY = -2
|
||||
FASM_STACK_OVERFLOW = -3
|
||||
FASM_SOURCE_NOT_FOUND = -4
|
||||
FASM_UNEXPECTED_END_OF_SOURCE = -5
|
||||
FASM_CANNOT_GENERATE_CODE = -6
|
||||
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
|
||||
FASM_WRITE_FAILED = -8
|
||||
FASM_INVALID_DEFINITION = -9
|
||||
|
||||
; Error codes for FASM_ERROR condition
|
||||
|
||||
FASMERR_FILE_NOT_FOUND = -101
|
||||
FASMERR_ERROR_READING_FILE = -102
|
||||
FASMERR_INVALID_FILE_FORMAT = -103
|
||||
FASMERR_INVALID_MACRO_ARGUMENTS = -104
|
||||
FASMERR_INCOMPLETE_MACRO = -105
|
||||
FASMERR_UNEXPECTED_CHARACTERS = -106
|
||||
FASMERR_INVALID_ARGUMENT = -107
|
||||
FASMERR_ILLEGAL_INSTRUCTION = -108
|
||||
FASMERR_INVALID_OPERAND = -109
|
||||
FASMERR_INVALID_OPERAND_SIZE = -110
|
||||
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
|
||||
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
|
||||
FASMERR_INVALID_ADDRESS_SIZE = -113
|
||||
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
|
||||
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
|
||||
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
|
||||
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
|
||||
FASMERR_INVALID_EXPRESSION = -118
|
||||
FASMERR_INVALID_ADDRESS = -119
|
||||
FASMERR_INVALID_VALUE = -120
|
||||
FASMERR_VALUE_OUT_OF_RANGE = -121
|
||||
FASMERR_UNDEFINED_SYMBOL = -122
|
||||
FASMERR_INVALID_USE_OF_SYMBOL = -123
|
||||
FASMERR_NAME_TOO_LONG = -124
|
||||
FASMERR_INVALID_NAME = -125
|
||||
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
|
||||
FASMERR_SYMBOL_ALREADY_DEFINED = -127
|
||||
FASMERR_MISSING_END_QUOTE = -128
|
||||
FASMERR_MISSING_END_DIRECTIVE = -129
|
||||
FASMERR_UNEXPECTED_INSTRUCTION = -130
|
||||
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
|
||||
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
|
||||
FASMERR_SETTING_ALREADY_SPECIFIED = -133
|
||||
FASMERR_DATA_ALREADY_DEFINED = -134
|
||||
FASMERR_TOO_MANY_REPEATS = -135
|
||||
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
|
||||
FASMERR_USER_ERROR = -140
|
||||
FASMERR_ASSERTION_FAILED = -141
|
||||
458
FasmDll/SOURCE/DLL/FASM.ASM
Normal file
458
FasmDll/SOURCE/DLL/FASM.ASM
Normal file
@@ -0,0 +1,458 @@
|
||||
|
||||
; flat assembler DLL interface for Win32
|
||||
; Copyright (c) 1999-2017, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
format PE DLL GUI 4.0
|
||||
entry DLLEntryPoint
|
||||
|
||||
include 'win32a.inc'
|
||||
include 'fasm.ash'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
include '..\variable.inc'
|
||||
|
||||
state dd ?
|
||||
esp_save dd ?
|
||||
source dd ?
|
||||
source_position dd ?
|
||||
first_write dd ?
|
||||
first_write_length dd ?
|
||||
second_write dd ?
|
||||
second_write_length dd ?
|
||||
display_pipe dd ?
|
||||
|
||||
systime SYSTEMTIME
|
||||
|
||||
tmp dd ?
|
||||
buffer rb 1000h
|
||||
|
||||
section '.text' code readable executable
|
||||
|
||||
DLLEntryPoint:
|
||||
mov eax,TRUE
|
||||
ret 12
|
||||
|
||||
fasm_GetVersion:
|
||||
mov eax,VERSION_MAJOR + VERSION_MINOR shl 16
|
||||
ret
|
||||
|
||||
fasm_AssembleFile:
|
||||
|
||||
mov eax,[lpSource]
|
||||
mov [input_file],eax
|
||||
mov [output_file],null_byte
|
||||
|
||||
jmp setup_assembler
|
||||
|
||||
fasm_Assemble:
|
||||
|
||||
virtual at esp+4
|
||||
lpSource dd ?
|
||||
lpMemory dd ?
|
||||
cbMemorySize dd ?
|
||||
nPassesLimit dd ?
|
||||
hDisplayPipe dd ?
|
||||
end virtual
|
||||
|
||||
mov eax,[lpSource]
|
||||
mov [source],eax
|
||||
mov [source_position],0
|
||||
|
||||
mov [input_file],null_byte
|
||||
mov [output_file],null_byte
|
||||
|
||||
setup_assembler:
|
||||
|
||||
mov eax,[nPassesLimit]
|
||||
cmp eax,10000h
|
||||
ja invalid_parameter
|
||||
or eax,eax
|
||||
jz invalid_parameter
|
||||
mov [passes_limit],ax
|
||||
|
||||
mov eax,[lpMemory]
|
||||
mov ecx,[cbMemorySize]
|
||||
mov [state],eax
|
||||
mov [eax+FASM_STATE.condition],FASM_WORKING
|
||||
sub ecx,sizeof.FASM_STATE
|
||||
jbe out_of_memory
|
||||
add eax,sizeof.FASM_STATE
|
||||
mov [memory_start],eax
|
||||
mov edx,ecx
|
||||
shr edx,2
|
||||
sub ecx,edx
|
||||
add eax,ecx
|
||||
mov [memory_end],eax
|
||||
mov [additional_memory],eax
|
||||
add eax,edx
|
||||
mov [additional_memory_end],eax
|
||||
|
||||
xor eax,eax
|
||||
mov [initial_definitions],eax
|
||||
|
||||
mov [first_write],eax
|
||||
mov [second_write],eax
|
||||
|
||||
mov eax,[hDisplayPipe]
|
||||
mov [display_pipe],eax
|
||||
|
||||
push ebp ebx esi edi
|
||||
mov eax,esp
|
||||
mov [esp_save],eax
|
||||
and eax,not 0FFFh
|
||||
add eax,1000h-10000h
|
||||
mov [stack_limit],eax
|
||||
|
||||
call preprocessor
|
||||
call parser
|
||||
call assembler
|
||||
call formatter
|
||||
|
||||
mov ebx,[state]
|
||||
mov [ebx+FASM_STATE.condition],FASM_OK
|
||||
|
||||
done:
|
||||
mov eax,[ebx+FASM_STATE.condition]
|
||||
pop edi esi ebx ebp
|
||||
ret 20
|
||||
|
||||
general_error:
|
||||
mov esp,[esp_save]
|
||||
mov ebx,[state]
|
||||
mov [ebx+FASM_STATE.condition],eax
|
||||
jmp done
|
||||
|
||||
assembler_error:
|
||||
mov esp,[esp_save]
|
||||
mov ebx,[state]
|
||||
mov [ebx+FASM_STATE.error_code],eax
|
||||
mov eax,[current_line]
|
||||
mov [ebx+FASM_STATE.error_line],eax
|
||||
mov eax,FASM_ERROR
|
||||
jmp general_error
|
||||
|
||||
get_environment_variable:
|
||||
invoke GetEnvironmentVariable,esi,buffer,1000h
|
||||
retn
|
||||
|
||||
open:
|
||||
cmp byte [edx],0
|
||||
je open_memory
|
||||
invoke CreateFile,edx,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
|
||||
cmp eax,-1
|
||||
je file_error
|
||||
mov ebx,eax
|
||||
clc
|
||||
retn
|
||||
file_error:
|
||||
stc
|
||||
retn
|
||||
open_memory:
|
||||
xor ebx,ebx
|
||||
retn
|
||||
read:
|
||||
or ebx,ebx
|
||||
jz read_memory
|
||||
mov ebp,ecx
|
||||
invoke ReadFile,ebx,edx,ecx,tmp,0
|
||||
or eax,eax
|
||||
jz file_error
|
||||
cmp ebp,[tmp]
|
||||
jne file_error
|
||||
clc
|
||||
retn
|
||||
read_memory:
|
||||
push esi edi
|
||||
mov esi,[source]
|
||||
add esi,[source_position]
|
||||
mov edi,edx
|
||||
call move_block
|
||||
pop edi esi
|
||||
clc
|
||||
retn
|
||||
move_block:
|
||||
mov al,cl
|
||||
shr ecx,2
|
||||
rep movsd
|
||||
mov cl,al
|
||||
and cl,11b
|
||||
rep movsb
|
||||
retn
|
||||
lseek:
|
||||
or ebx,ebx
|
||||
jz seek_memory
|
||||
movzx eax,al
|
||||
invoke SetFilePointer,ebx,edx,0,eax
|
||||
cmp eax,-1
|
||||
je file_error
|
||||
retn
|
||||
seek_memory:
|
||||
push esi
|
||||
mov esi,[source]
|
||||
mov ecx,edx
|
||||
or al,al
|
||||
jz seek_forward
|
||||
add esi,[source_position]
|
||||
cmp al,2
|
||||
je seek_source_end
|
||||
seek_forward:
|
||||
sub ecx,1
|
||||
jc seek_complete
|
||||
seek_in_source:
|
||||
lodsb
|
||||
or al,al
|
||||
loopnz seek_in_source
|
||||
jnz seek_complete
|
||||
dec esi
|
||||
seek_complete:
|
||||
mov eax,esi
|
||||
sub eax,[source]
|
||||
mov [source_position],eax
|
||||
pop esi
|
||||
retn
|
||||
seek_source_end:
|
||||
lodsb
|
||||
or al,al
|
||||
jnz seek_source_end
|
||||
dec esi
|
||||
sub esi,edx
|
||||
cmp esi,[source]
|
||||
jae seek_complete
|
||||
mov esi,[source]
|
||||
jmp seek_complete
|
||||
create:
|
||||
or ebx,-1
|
||||
clc
|
||||
retn
|
||||
write:
|
||||
cmp [first_write],0
|
||||
jne make_second_write
|
||||
mov [first_write],edx
|
||||
mov [first_write_length],ecx
|
||||
clc
|
||||
retn
|
||||
make_second_write:
|
||||
cmp [second_write],0
|
||||
jne cannot_write
|
||||
mov [second_write],edx
|
||||
mov [second_write_length],ecx
|
||||
clc
|
||||
retn
|
||||
cannot_write:
|
||||
stc
|
||||
retn
|
||||
close:
|
||||
or ebx,ebx
|
||||
jz file_closed
|
||||
cmp ebx,-1
|
||||
je output_ready
|
||||
invoke CloseHandle,ebx
|
||||
file_closed:
|
||||
retn
|
||||
output_ready:
|
||||
mov ebx,[state]
|
||||
cmp [second_write],0
|
||||
jne two_part_output
|
||||
mov eax,[first_write]
|
||||
mov [ebx+FASM_STATE.output_data],eax
|
||||
mov eax,[first_write_length]
|
||||
mov [ebx+FASM_STATE.output_length],eax
|
||||
retn
|
||||
two_part_output:
|
||||
mov eax,[second_write]
|
||||
mov [ebx+FASM_STATE.output_data],eax
|
||||
shuffle_output:
|
||||
mov ecx,[first_write_length]
|
||||
cmp ecx,[second_write_length]
|
||||
ja small_second_part
|
||||
sub [second_write_length],ecx
|
||||
mov esi,[first_write]
|
||||
mov edi,[second_write]
|
||||
call xchg_block
|
||||
mov [second_write],edi
|
||||
jmp shuffle_output
|
||||
xchg_block:
|
||||
shr ecx,1
|
||||
jnc xchgb_ok
|
||||
mov al,[edi]
|
||||
xchg al,[esi]
|
||||
stosb
|
||||
inc esi
|
||||
xchgb_ok:
|
||||
shr ecx,1
|
||||
jnc xchgw_ok
|
||||
mov ax,[edi]
|
||||
xchg ax,[esi]
|
||||
stosw
|
||||
add esi,2
|
||||
xchgw_ok:
|
||||
jz xchgd_ok
|
||||
xchgd:
|
||||
mov eax,[edi]
|
||||
xchg eax,[esi]
|
||||
stosd
|
||||
add esi,4
|
||||
loop xchgd
|
||||
xchgd_ok:
|
||||
retn
|
||||
small_second_part:
|
||||
mov edi,[second_write]
|
||||
mov esi,edi
|
||||
add edi,[first_write_length]
|
||||
cmp edi,[first_write]
|
||||
jbe move_second_part
|
||||
mov edi,[first_write]
|
||||
add edi,[first_write_length]
|
||||
move_second_part:
|
||||
push edi
|
||||
mov ecx,[second_write_length]
|
||||
lea eax,[edi+ecx]
|
||||
cmp eax,[tagged_blocks]
|
||||
ja out_of_memory
|
||||
call move_block
|
||||
mov edi,[second_write]
|
||||
mov esi,[first_write]
|
||||
mov ecx,[first_write_length]
|
||||
call move_block
|
||||
pop esi
|
||||
mov ecx,[second_write_length]
|
||||
call move_block
|
||||
mov ecx,edi
|
||||
sub ecx,[ebx+FASM_STATE.output_data]
|
||||
mov [ebx+FASM_STATE.output_length],ecx
|
||||
retn
|
||||
|
||||
display_block:
|
||||
mov eax,[display_pipe]
|
||||
or eax,eax
|
||||
jz display_ok
|
||||
invoke WriteFile,eax,esi,ecx,tmp,NULL
|
||||
display_ok:
|
||||
retn
|
||||
|
||||
make_timestamp:
|
||||
invoke GetSystemTime,systime
|
||||
movzx ecx,[systime.wYear]
|
||||
mov eax,ecx
|
||||
sub eax,1970
|
||||
mov ebx,365
|
||||
mul ebx
|
||||
mov ebp,eax
|
||||
mov eax,ecx
|
||||
sub eax,1969
|
||||
shr eax,2
|
||||
add ebp,eax
|
||||
mov eax,ecx
|
||||
sub eax,1901
|
||||
mov ebx,100
|
||||
div ebx
|
||||
sub ebp,eax
|
||||
mov eax,ecx
|
||||
xor edx,edx
|
||||
sub eax,1601
|
||||
mov ebx,400
|
||||
div ebx
|
||||
add ebp,eax
|
||||
movzx ecx,[systime.wMonth]
|
||||
mov eax,ecx
|
||||
dec eax
|
||||
mov ebx,30
|
||||
mul ebx
|
||||
add ebp,eax
|
||||
cmp ecx,8
|
||||
jbe months_correction
|
||||
mov eax,ecx
|
||||
sub eax,7
|
||||
shr eax,1
|
||||
add ebp,eax
|
||||
mov ecx,8
|
||||
months_correction:
|
||||
mov eax,ecx
|
||||
shr eax,1
|
||||
add ebp,eax
|
||||
cmp ecx,2
|
||||
jbe day_correction_ok
|
||||
sub ebp,2
|
||||
movzx ecx,word [systime.wYear]
|
||||
test ecx,11b
|
||||
jnz day_correction_ok
|
||||
xor edx,edx
|
||||
mov eax,ecx
|
||||
mov ebx,100
|
||||
div ebx
|
||||
or edx,edx
|
||||
jnz day_correction
|
||||
mov eax,ecx
|
||||
mov ebx,400
|
||||
div ebx
|
||||
or edx,edx
|
||||
jnz day_correction_ok
|
||||
day_correction:
|
||||
inc ebp
|
||||
day_correction_ok:
|
||||
movzx eax,[systime.wDay]
|
||||
dec eax
|
||||
add eax,ebp
|
||||
mov ebx,24
|
||||
mul ebx
|
||||
movzx ecx,[systime.wHour]
|
||||
add eax,ecx
|
||||
mov ebx,60
|
||||
mul ebx
|
||||
movzx ecx,[systime.wMinute]
|
||||
add eax,ecx
|
||||
mov ebx,60
|
||||
mul ebx
|
||||
movzx ecx,[systime.wSecond]
|
||||
add eax,ecx
|
||||
retn
|
||||
|
||||
dump_symbols:
|
||||
retn
|
||||
|
||||
include 'errors.inc'
|
||||
|
||||
include '..\preproce.inc'
|
||||
include '..\parser.inc'
|
||||
include '..\exprpars.inc'
|
||||
include '..\exprcalc.inc'
|
||||
include '..\assemble.inc'
|
||||
include '..\formats.inc'
|
||||
include '..\x86_64.inc'
|
||||
include '..\avx.inc'
|
||||
include '..\tables.inc'
|
||||
|
||||
include '..\version.inc'
|
||||
|
||||
null_byte db 0
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel32,'KERNEL32.DLL'
|
||||
|
||||
include 'api\kernel32.inc'
|
||||
|
||||
section '.edata' export data readable
|
||||
|
||||
export 'FASM.DLL',\
|
||||
fasm_GetVersion,'fasm_GetVersion',\
|
||||
fasm_Assemble,'fasm_Assemble',\
|
||||
fasm_AssembleFile,'fasm_AssembleFile'
|
||||
|
||||
section '.reloc' fixups data readable discardable
|
||||
|
||||
section '.rsrc' resource data readable
|
||||
|
||||
directory RT_VERSION,versions
|
||||
|
||||
resource versions,\
|
||||
1,LANG_NEUTRAL,version
|
||||
|
||||
versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
|
||||
'FileDescription','flat assembler',\
|
||||
'LegalCopyright',<'Copyright ',0A9h,' 2001-2017 Tomasz Grysztar.'>,\
|
||||
'FileVersion',VERSION_STRING,\
|
||||
'ProductVersion',VERSION_STRING,\
|
||||
'OriginalFilename','FASM.DLL'
|
||||
195
FasmDll/SOURCE/IDE/FASMW/FEDIT.ASM
Normal file
195
FasmDll/SOURCE/IDE/FASMW/FEDIT.ASM
Normal file
@@ -0,0 +1,195 @@
|
||||
|
||||
; flat editor DLL interface for Win32
|
||||
; Copyright (c) 2001-2014, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
format PE DLL GUI 4.0
|
||||
entry DLLEntryPoint
|
||||
|
||||
include 'win32a.inc'
|
||||
|
||||
include 'fedit.ash'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
_fedit_class db 'FEDIT',0
|
||||
|
||||
_user_library db 'USER32.DLL',0
|
||||
_setgestureconfig_api db 'SetGestureConfig',0
|
||||
_getgestureinfo_api db 'GetGestureInfo',0
|
||||
_closegestureinfohandle_api db 'CloseGestureInfoHandle',0
|
||||
|
||||
align 4
|
||||
|
||||
SetGestureConfig dd 0
|
||||
GetGestureInfo dd 0
|
||||
CloseGestureInfoHandle dd 0
|
||||
|
||||
wheel_scroll_lines dd 3
|
||||
|
||||
fedit_font dd ?
|
||||
|
||||
char rb 4
|
||||
kbstate rb 100h
|
||||
line_colors rb 100h
|
||||
line_buffer rb 100h
|
||||
text_buffer rb 100h
|
||||
upper_case_table rb 100h
|
||||
|
||||
wc WNDCLASS
|
||||
ps PAINTSTRUCT
|
||||
tm TEXTMETRIC
|
||||
sc SCROLLINFO
|
||||
rect RECT
|
||||
|
||||
section '.text' code readable executable
|
||||
|
||||
proc DLLEntryPoint uses ebx esi edi,hinstDLL,fdwReason,lpvReserved
|
||||
cmp [fdwReason],DLL_PROCESS_ATTACH
|
||||
jne .done
|
||||
invoke GetModuleHandle,_user_library
|
||||
or eax,eax
|
||||
jz .gesture_api_unavailable
|
||||
mov ebx,eax
|
||||
invoke GetProcAddress,ebx,_setgestureconfig_api
|
||||
or eax,eax
|
||||
jz .gesture_api_unavailable
|
||||
mov esi,eax
|
||||
invoke GetProcAddress,ebx,_getgestureinfo_api
|
||||
or eax,eax
|
||||
jz .gesture_api_unavailable
|
||||
mov edi,eax
|
||||
invoke GetProcAddress,ebx,_closegestureinfohandle_api
|
||||
or eax,eax
|
||||
jz .gesture_api_unavailable
|
||||
mov [CloseGestureInfoHandle],eax
|
||||
mov [SetGestureConfig],esi
|
||||
mov [GetGestureInfo],edi
|
||||
.gesture_api_unavailable:
|
||||
invoke LoadCursor,0,IDC_IBEAM
|
||||
mov [wc.hCursor],eax
|
||||
mov [wc.style],CS_GLOBALCLASS+CS_DBLCLKS
|
||||
mov [wc.lpfnWndProc],FlatEditor
|
||||
mov eax,[hinstDLL]
|
||||
mov [wc.hInstance],eax
|
||||
mov [wc.cbWndExtra],4
|
||||
xor eax,eax
|
||||
mov [wc.hbrBackground],eax
|
||||
mov [wc.cbClsExtra],eax
|
||||
mov [wc.lpszMenuName],eax
|
||||
mov [wc.lpszClassName],_fedit_class
|
||||
invoke RegisterClass,wc
|
||||
or eax,eax
|
||||
jz .failed
|
||||
invoke CreateFont,0,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL
|
||||
or eax,eax
|
||||
jz .failed
|
||||
mov [fedit_font],eax
|
||||
push ebx esi edi
|
||||
mov edi,upper_case_table
|
||||
xor ebx,ebx
|
||||
mov esi,100h
|
||||
.make_upper_case_table:
|
||||
invoke CharUpper,ebx
|
||||
stosb
|
||||
inc bl
|
||||
dec esi
|
||||
jnz .make_upper_case_table
|
||||
pop edi esi ebx
|
||||
.done:
|
||||
mov eax,TRUE
|
||||
ret
|
||||
.failed:
|
||||
mov eax,FALSE
|
||||
ret
|
||||
endp
|
||||
|
||||
include 'fedit.inc'
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel,'KERNEL32.DLL',\
|
||||
user,'USER32.DLL',\
|
||||
gdi,'GDI32.DLL'
|
||||
|
||||
import kernel,\
|
||||
GetModuleHandle,'GetModuleHandleA',\
|
||||
GetProcAddress,'GetProcAddress',\
|
||||
GlobalAlloc,'GlobalAlloc',\
|
||||
GlobalReAlloc,'GlobalReAlloc',\
|
||||
GlobalLock,'GlobalLock',\
|
||||
GlobalUnlock,'GlobalUnlock',\
|
||||
GlobalFree,'GlobalFree',\
|
||||
VirtualAlloc,'VirtualAlloc',\
|
||||
VirtualFree,'VirtualFree',\
|
||||
ExitProcess,'ExitProcess'
|
||||
|
||||
import user,\
|
||||
RegisterClass,'RegisterClassA',\
|
||||
CreateCaret,'CreateCaret',\
|
||||
ShowCaret,'ShowCaret',\
|
||||
HideCaret,'HideCaret',\
|
||||
SetCaretPos,'SetCaretPos',\
|
||||
DestroyCaret,'DestroyCaret',\
|
||||
BeginPaint,'BeginPaint',\
|
||||
EndPaint,'EndPaint',\
|
||||
GetDC,'GetDC',\
|
||||
GetUpdateRect,'GetUpdateRect',\
|
||||
ReleaseDC,'ReleaseDC',\
|
||||
GetCursorPos,'GetCursorPos',\
|
||||
ClientToScreen,'ClientToScreen',\
|
||||
TrackPopupMenu,'TrackPopupMenu',\
|
||||
DrawText,'DrawTextA',\
|
||||
FillRect,'FillRect',\
|
||||
InvalidateRect,'InvalidateRect',\
|
||||
GetKeyboardState,'GetKeyboardState',\
|
||||
ToAscii,'ToAscii',\
|
||||
GetScrollInfo,'GetScrollInfo',\
|
||||
SetScrollInfo,'SetScrollInfo',\
|
||||
SetCapture,'SetCapture',\
|
||||
ReleaseCapture,'ReleaseCapture',\
|
||||
OpenClipboard,'OpenClipboard',\
|
||||
CloseClipboard,'CloseClipboard',\
|
||||
EmptyClipboard,'EmptyClipboard',\
|
||||
GetClipboardData,'GetClipboardData',\
|
||||
SetClipboardData,'SetClipboardData',\
|
||||
LoadCursor,'LoadCursorA',\
|
||||
IsClipboardFormatAvailable,'IsClipboardFormatAvailable',\
|
||||
CharUpper,'CharUpperA',\
|
||||
GetWindowLong,'GetWindowLongA',\
|
||||
SetWindowLong,'SetWindowLongA',\
|
||||
DefWindowProc,'DefWindowProcA',\
|
||||
GetClientRect,'GetClientRect',\
|
||||
UpdateWindow,'UpdateWindow',\
|
||||
SetFocus,'SetFocus',\
|
||||
GetSysColor,'GetSysColor',\
|
||||
MessageBox,'MessageBoxA',\
|
||||
SendMessage,'SendMessageA',\
|
||||
PostMessage,'PostMessageA'
|
||||
|
||||
import gdi,\
|
||||
SetBkColor,'SetBkColor',\
|
||||
SetTextColor,'SetTextColor',\
|
||||
CreateSolidBrush,'CreateSolidBrush',\
|
||||
CreateFont,'CreateFontA',\
|
||||
GetTextMetrics,'GetTextMetricsA',\
|
||||
GetTextExtentPoint32,'GetTextExtentPoint32A',\
|
||||
DeleteDC,'DeleteDC',\
|
||||
SelectObject,'SelectObject',\
|
||||
DeleteObject,'DeleteObject'
|
||||
|
||||
section '.reloc' fixups data readable discardable
|
||||
|
||||
section '.rsrc' resource data readable
|
||||
|
||||
directory RT_VERSION,versions
|
||||
|
||||
resource versions,\
|
||||
1,LANG_NEUTRAL,version
|
||||
|
||||
versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
|
||||
'FileDescription','flat editor',\
|
||||
'LegalCopyright',<'Copyright ',0A9h,' 1999-2014 Tomasz Grysztar.'>,\
|
||||
'FileVersion',FEDIT_VERSION_STRING,\
|
||||
'ProductVersion',FEDIT_VERSION_STRING,\
|
||||
'OriginalFilename','FEDIT.DLL'
|
||||
Reference in New Issue
Block a user