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
|
||||
Reference in New Issue
Block a user