├── FASM.EXE ├── FASM.PDF ├── FASMW.EXE ├── EXTENSIONS ├── FASM.DLL ├── FASM.OBJ ├── FASM.h ├── ERRORS.INC └── FASM.ASH ├── EXAMPLES ├── DDRAW │ ├── DDRAW.GIF │ └── GIF87A.INC ├── MINIPAD │ ├── MINIPAD.ICO │ └── MINIPAD.ASM ├── MSCOFF │ └── MSCOFF.ASM ├── HELLO │ └── HELLO.ASM ├── DLL │ ├── LASTERR.ASM │ └── ERRORMSG.ASM ├── WIN64 │ ├── DLL │ │ ├── MSGDEMO.ASM │ │ └── WRITEMSG.ASM │ ├── PE64DEMO │ │ └── PE64DEMO.ASM │ ├── WIN64AVX │ │ └── WIN64AVX.ASM │ ├── TEMPLATE │ │ └── TEMPLATE.ASM │ └── USECOM │ │ └── USECOM.ASM ├── PEDEMO │ └── PEDEMO.ASM ├── TEMPLATE │ └── TEMPLATE.ASM ├── USECOM │ └── USECOM.ASM └── DIALOG │ └── DIALOG.ASM ├── SOURCE ├── IDE │ ├── FASMD │ │ └── FASMD.ASM │ ├── FASMW │ │ ├── RESOURCE │ │ │ ├── ASSIGN.BMP │ │ │ └── FASMW.ICO │ │ └── FEDIT.ASH │ ├── VARIABLE.INC │ ├── VERSION.INC │ └── MEMORY.INC ├── VERSION.INC ├── DOS │ └── DPMI.INC ├── MESSAGES.INC ├── VARIABLE.INC ├── LINUX │ └── X64 │ │ └── MODES.INC └── ERRORS.INC ├── .gitignore ├── BUILD_EXT.BAT ├── INCLUDE ├── PCOUNT │ ├── COMDLG32.INC │ ├── WSOCK32.INC │ ├── SHELL32.INC │ └── COMCTL32.INC ├── WIN64W.INC ├── WIN64A.INC ├── WIN32W.INC ├── WIN32A.INC ├── ENCODING │ ├── WIN874.INC │ ├── WIN1252.INC │ ├── WIN1253.INC │ ├── WIN1251.INC │ ├── WIN1254.INC │ ├── WIN1255.INC │ ├── WIN1257.INC │ ├── WIN1258.INC │ ├── WIN1250.INC │ ├── WIN1256.INC │ └── UTF8.INC ├── MACRO │ ├── COM64.INC │ ├── COM32.INC │ ├── IMPORT32.INC │ ├── IMPORT64.INC │ ├── EXPORT.INC │ └── MASM.INC ├── API │ ├── COMDLG32.INC │ ├── WSOCK32.INC │ └── COMCTL32.INC ├── EQUATES │ ├── WSOCK32.INC │ ├── SHELL32.INC │ └── SHELL64.INC ├── WIN32AX.INC ├── WIN32WX.INC ├── WIN64WX.INC ├── WIN64AX.INC ├── WIN32AXP.INC ├── WIN32WXP.INC ├── WIN64AXP.INC └── WIN64WXP.INC ├── TOOLS ├── LIBC │ ├── CCALL.INC │ ├── PREPSRC.ASM │ ├── SYMBOLS.ASM │ ├── SYSTEM.INC │ └── LISTING.ASM ├── README.TXT ├── WIN32 │ ├── SYSTEM.INC │ ├── PREPSRC.ASM │ ├── SYMBOLS.ASM │ └── LISTING.ASM ├── DOS │ ├── LOADER.INC │ ├── PREPSRC.ASM │ ├── SYMBOLS.ASM │ ├── SYSTEM.INC │ └── LISTING.ASM └── PREPSRC.INC ├── README.md └── LICENSE.TXT /FASM.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/FASM.EXE -------------------------------------------------------------------------------- /FASM.PDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/FASM.PDF -------------------------------------------------------------------------------- /FASMW.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/FASMW.EXE -------------------------------------------------------------------------------- /EXTENSIONS/FASM.DLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/EXTENSIONS/FASM.DLL -------------------------------------------------------------------------------- /EXTENSIONS/FASM.OBJ: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/EXTENSIONS/FASM.OBJ -------------------------------------------------------------------------------- /EXAMPLES/DDRAW/DDRAW.GIF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/EXAMPLES/DDRAW/DDRAW.GIF -------------------------------------------------------------------------------- /SOURCE/IDE/FASMD/FASMD.ASM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/SOURCE/IDE/FASMD/FASMD.ASM -------------------------------------------------------------------------------- /EXAMPLES/MINIPAD/MINIPAD.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/EXAMPLES/MINIPAD/MINIPAD.ICO -------------------------------------------------------------------------------- /SOURCE/IDE/FASMW/RESOURCE/ASSIGN.BMP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/SOURCE/IDE/FASMW/RESOURCE/ASSIGN.BMP -------------------------------------------------------------------------------- /SOURCE/IDE/FASMW/RESOURCE/FASMW.ICO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Konctantin/FASM/HEAD/SOURCE/IDE/FASMW/RESOURCE/FASMW.ICO -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.exe 3 | *.dll 4 | *.obj 5 | *.bin 6 | *.fas 7 | *.ini 8 | 9 | !FASM.EXE 10 | !FASMW.EXE 11 | !FASM.OBJ 12 | !FASM.DLL 13 | -------------------------------------------------------------------------------- /BUILD_EXT.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | set include=SOURCE;INCLUDE 3 | FASM.EXE EXTENSIONS\FASMD.ASM EXTENSIONS\FASM.DLL 4 | FASM.EXE EXTENSIONS\FASMO.ASM EXTENSIONS\FASM.OBJ 5 | pause -------------------------------------------------------------------------------- /INCLUDE/PCOUNT/COMDLG32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; COMDLG32 API calls parameters' count 3 | 4 | ChooseColor% = 1 5 | ChooseFont% = 1 6 | CommDlgExtendedError% = 0 7 | FindText% = 1 8 | FormatCharDlgProc% = 4 9 | GetFileTitle% = 3 10 | GetOpenFileName% = 1 11 | GetSaveFileName% = 1 12 | LoadAlterBitmap% = 3 13 | PageSetupDlg% = 1 14 | PrintDlg% = 1 15 | ReplaceText% = 1 16 | WantArrows% = 4 17 | dwLBSubclass% = 4 18 | dwOKSubclass% = 4 19 | -------------------------------------------------------------------------------- /TOOLS/LIBC/CCALL.INC: -------------------------------------------------------------------------------- 1 | 2 | macro ccall proc,[arg] 3 | { common 4 | push ebp 5 | mov ebp,esp 6 | local size 7 | size = 0 8 | if ~ arg eq 9 | forward 10 | size = size + 4 11 | common 12 | sub esp,size 13 | end if 14 | and esp,-16 15 | if ~ arg eq 16 | add esp,size 17 | reverse 18 | pushd arg 19 | common 20 | end if 21 | call proc 22 | leave } 23 | 24 | -------------------------------------------------------------------------------- /EXAMPLES/MSCOFF/MSCOFF.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; example of making Win32 COFF object file 3 | 4 | format MS COFF 5 | 6 | extrn '__imp__MessageBoxA@16' as MessageBox:dword 7 | 8 | section '.text' code readable executable 9 | 10 | public _demo 11 | 12 | _demo: 13 | push 0 14 | push _caption 15 | push _message 16 | push 0 17 | call [MessageBox] 18 | ret 19 | 20 | section '.data' data readable writeable 21 | 22 | _caption db 'Win32 assembly',0 23 | _message db 'Coffee time!',0 24 | -------------------------------------------------------------------------------- /EXAMPLES/HELLO/HELLO.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; example of simplified Windows programming using complex macro features 3 | 4 | include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here 5 | 6 | .code 7 | 8 | start: 9 | 10 | invoke MessageBox,HWND_DESKTOP,"May I introduce myself?",invoke GetCommandLine,MB_YESNO 11 | 12 | .if eax = IDYES 13 | invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!","Hello!",MB_OK 14 | .endif 15 | 16 | invoke ExitProcess,0 17 | 18 | .end start 19 | -------------------------------------------------------------------------------- /EXAMPLES/DLL/LASTERR.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE GUI 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.text' code readable executable 8 | 9 | start: 10 | invoke SetLastError,0 11 | invoke ShowLastError,HWND_DESKTOP 12 | invoke ExitProcess,0 13 | 14 | section '.idata' import data readable writeable 15 | 16 | library kernel,'KERNEL32.DLL',\ 17 | errormsg,'ERRORMSG.DLL' 18 | 19 | import kernel,\ 20 | SetLastError,'SetLastError',\ 21 | ExitProcess,'ExitProcess' 22 | 23 | import errormsg,\ 24 | ShowLastError,'ShowLastError' 25 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/DLL/MSGDEMO.ASM: -------------------------------------------------------------------------------- 1 | format PE64 console 2 | entry start 3 | 4 | include 'win64a.inc' 5 | 6 | section '.text' code readable executable 7 | 8 | start: 9 | sub rsp,8 10 | 11 | invoke WriteMessage,message 12 | 13 | invoke ExitProcess,0 14 | 15 | section '.data' data readable 16 | 17 | message db "Hi! I'm the example program!",0 18 | 19 | section '.idata' import data readable writeable 20 | 21 | library kernel32,'KERNEL32.DLL',\ 22 | writemsg,'WRITEMSG.DLL' 23 | 24 | include 'api/kernel32.inc' 25 | 26 | import writemsg,\ 27 | WriteMessage,'WriteMessage' -------------------------------------------------------------------------------- /INCLUDE/WIN64W.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Win64 programming headers (WideChar) 3 | 4 | include 'macro/struct.inc' 5 | include 'macro/proc64.inc' 6 | include 'macro/com64.inc' 7 | include 'macro/import64.inc' 8 | include 'macro/export.inc' 9 | include 'macro/resource.inc' 10 | 11 | struc TCHAR [val] { common match any, val \{ . du val \} 12 | match , val \{ . du ? \} } 13 | sizeof.TCHAR = 2 14 | 15 | include 'equates/kernel64.inc' 16 | include 'equates/user64.inc' 17 | include 'equates/gdi64.inc' 18 | include 'equates/comctl64.inc' 19 | include 'equates/comdlg64.inc' 20 | include 'equates/shell64.inc' 21 | 22 | macro api [name] { if used name 23 | label name qword at name#W 24 | end if } -------------------------------------------------------------------------------- /INCLUDE/WIN64A.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Win64 programming headers (ASCII) 3 | 4 | include 'macro/struct.inc' 5 | include 'macro/proc64.inc' 6 | include 'macro/com64.inc' 7 | include 'macro/import64.inc' 8 | include 'macro/export.inc' 9 | include 'macro/resource.inc' 10 | 11 | struc TCHAR [val] { common match any, val \{ . db val \} 12 | match , val \{ . db ? \} } 13 | sizeof.TCHAR = 1 14 | 15 | include 'equates/kernel64.inc' 16 | include 'equates/user64.inc' 17 | include 'equates/gdi64.inc' 18 | include 'equates/comctl64.inc' 19 | include 'equates/comdlg64.inc' 20 | include 'equates/shell64.inc' 21 | 22 | macro api [name] { if used name 23 | label name qword at name#A 24 | end if } 25 | 26 | -------------------------------------------------------------------------------- /INCLUDE/WIN32W.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Win32 programming headers (WideChar) 3 | 4 | include 'macro/struct.inc' 5 | include 'macro/proc32.inc' 6 | include 'macro/com32.inc' 7 | include 'macro/import32.inc' 8 | include 'macro/export.inc' 9 | include 'macro/resource.inc' 10 | 11 | struc TCHAR [val] { common match any, val \{ . du val \} 12 | match , val \{ . du ? \} } 13 | sizeof.TCHAR = 2 14 | 15 | include 'equates/kernel32.inc' 16 | include 'equates/user32.inc' 17 | include 'equates/gdi32.inc' 18 | include 'equates/comctl32.inc' 19 | include 'equates/comdlg32.inc' 20 | include 'equates/shell32.inc' 21 | include 'equates/wsock32.inc' 22 | 23 | macro api [name] { if used name 24 | label name dword at name#W 25 | end if } 26 | -------------------------------------------------------------------------------- /INCLUDE/WIN32A.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Win32 programming headers (ASCII) 3 | 4 | include 'macro/struct.inc' 5 | include 'macro/proc32.inc' 6 | include 'macro/com32.inc' 7 | include 'macro/import32.inc' 8 | include 'macro/export.inc' 9 | include 'macro/resource.inc' 10 | 11 | struc TCHAR [val] { common match any, val \{ . db val \} 12 | match , val \{ . db ? \} } 13 | sizeof.TCHAR = 1 14 | 15 | include 'equates/kernel32.inc' 16 | include 'equates/user32.inc' 17 | include 'equates/gdi32.inc' 18 | include 'equates/comctl32.inc' 19 | include 'equates/comdlg32.inc' 20 | include 'equates/shell32.inc' 21 | include 'equates/wsock32.inc' 22 | 23 | macro api [name] { if used name 24 | label name dword at name#A 25 | end if } 26 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN874.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 874 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,?,?,?,2026h,?,?,?,?,?,?,?,?,?,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,?,?,?,?,?,?,?,? 12 | times 60h dw 0E00h+%-1 13 | end virtual 14 | 15 | macro du [arg] 16 | { local offset,char 17 | offset = $-$$ 18 | du arg 19 | if arg eqtype '' 20 | repeat ($-offset-$$)/2 21 | load char byte from $$+offset+(%-1)*2 22 | if char > 7Fh 23 | load char word from __encoding:char*2 24 | store word char at $$+offset+(%-1)*2 25 | end if 26 | end repeat 27 | end if } 28 | 29 | struc du [args] 30 | { common label . word 31 | du args } 32 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1252.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1252 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,192h,201Eh,2026h,2020h,2021h,2C6h,2030h,160h,2039h,152h,?,17D,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,2DCh,2122h,161h,203Ah,153h,?,17Eh,178h 12 | times 60h dw 0A0h+%-1 13 | end virtual 14 | 15 | macro du [arg] 16 | { local offset,char 17 | offset = $-$$ 18 | du arg 19 | if arg eqtype '' 20 | repeat ($-offset-$$)/2 21 | load char byte from $$+offset+(%-1)*2 22 | if char > 7Fh 23 | load char word from __encoding:char*2 24 | store word char at $$+offset+(%-1)*2 25 | end if 26 | end repeat 27 | end if } 28 | 29 | struc du [args] 30 | { common label . word 31 | du args } 32 | -------------------------------------------------------------------------------- /SOURCE/IDE/VARIABLE.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat editor core 3 | ; Copyright (c) 1999-2015, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | editor_memory dd ? 7 | 8 | label editor_status 9 | 10 | first_line dd ? 11 | lines_count dd ? 12 | peak_line_length dd ? 13 | maximum_position dd ? 14 | window_line dd ? 15 | window_position dd ? 16 | window_line_number dd ? 17 | caret_line dd ? 18 | caret_position dd ? 19 | caret_line_number dd ? 20 | selection_line dd ? 21 | selection_position dd ? 22 | selection_line_number dd ? 23 | editor_mode dd ? 24 | 25 | editor_status_size = $ - editor_status 26 | 27 | window_width dd ? 28 | window_height dd ? 29 | unallocated_segments dd ? 30 | unallocated_segments_end dd ? 31 | released_segments dd ? 32 | memory_search_block dd ? 33 | memory_search_segment dd ? 34 | lengths_table dd ? 35 | undo_data dd ? 36 | redo_data dd ? 37 | search_data dd ? 38 | search_flags dd ? 39 | search_handle dd ? 40 | unmodified_state dd ? 41 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1253.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1253 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,192h,201Eh,2026h,2020h,2021h,?,2030h,?,2039h,?,?,?,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,?,2122h,?,203Ah,?,?,?,? 12 | dw 0A0h,385h,386h,0A3h,0A4h,0A5h,0A6h,0A7h,0A8h,0A9h,?,0ABh,0ACh,0ADh,0AEh,2015h 13 | dw 0B0h,0B1h,0B2h,0B3h,384h,0B5h,0B6h,0B7h,288h,389h,38Ah,0BBh,38Ch,0BDh,38Eh,38Fh 14 | times 40h dw 390h+%-1 15 | end virtual 16 | 17 | macro du [arg] 18 | { local offset,char 19 | offset = $-$$ 20 | du arg 21 | if arg eqtype '' 22 | repeat ($-offset-$$)/2 23 | load char byte from $$+offset+(%-1)*2 24 | if char > 7Fh 25 | load char word from __encoding:char*2 26 | store word char at $$+offset+(%-1)*2 27 | end if 28 | end repeat 29 | end if } 30 | 31 | struc du [args] 32 | { common label . word 33 | du args } 34 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1251.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1251 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 401h,403h,201Ah,453h,201Eh,2026h,2020h,2021h,20ACh,2030h,409h,2039h,40Ah,40Ch,40Bh,40Fh 11 | dw 452h,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,?,2122h,459h,203Ah,45Ah,45Ch,45Bh,45Fh 12 | dw 0A0h,40Eh,45Eh,408h,0A4h,490h,0A6h,0A7h,401h,0A9h,404h,0ABh,0ACh,0ADh,0AEh,407h 13 | dw 0B0h,0B1h,406h,456h,491h,0B5h,0B6h,0B7h,451h,2116h,454h,0BBh,458h,405h,455h,457h 14 | times 40h dw 410h+%-1 15 | end virtual 16 | 17 | macro du [arg] 18 | { local offset,char 19 | offset = $-$$ 20 | du arg 21 | if arg eqtype '' 22 | repeat ($-offset-$$)/2 23 | load char byte from $$+offset+(%-1)*2 24 | if char > 7Fh 25 | load char word from __encoding:char*2 26 | store word char at $$+offset+(%-1)*2 27 | end if 28 | end repeat 29 | end if } 30 | 31 | struc du [args] 32 | { common label . word 33 | du args } 34 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1254.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1254 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,192h,201Eh,2026h,2020h,2021h,2C6h,2030h,160h,2039h,152h,?,?,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,2DCh,2122h,161h,203Ah,153h,?,?,178h 12 | times 30h dw 0A0h+%-1 13 | dw 11Eh,0D1h,0D2h,0D3h,0D4h,0D5h,0D6h,0D7h,0D8h,0D9h,0DAh,0DBh,0DCh,130h,15Eh,0DFh 14 | times 10h dw 0E0h+%-1 15 | dw 11Fh,0F1h,0F2h,0F3h,0F4h,0F5h,0F6h,0F7h,0F8h,0F9h,0FAh,0FBh,0FCh,131h,15Fh,0FFh 16 | end virtual 17 | 18 | macro du [arg] 19 | { local offset,char 20 | offset = $-$$ 21 | du arg 22 | if arg eqtype '' 23 | repeat ($-offset-$$)/2 24 | load char byte from $$+offset+(%-1)*2 25 | if char > 7Fh 26 | load char word from __encoding:char*2 27 | store word char at $$+offset+(%-1)*2 28 | end if 29 | end repeat 30 | end if } 31 | 32 | struc du [args] 33 | { common label . word 34 | du args } 35 | -------------------------------------------------------------------------------- /EXAMPLES/PEDEMO/PEDEMO.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; Example of making 32-bit PE program as raw code and data 3 | 4 | format PE GUI 5 | entry start 6 | 7 | section '.text' code readable executable 8 | 9 | start: 10 | 11 | push 0 12 | push _caption 13 | push _message 14 | push 0 15 | call [MessageBoxA] 16 | 17 | push 0 18 | call [ExitProcess] 19 | 20 | section '.data' data readable writeable 21 | 22 | _caption db 'Win32 assembly program',0 23 | _message db 'Hello World!',0 24 | 25 | section '.idata' import data readable writeable 26 | 27 | dd 0,0,0,RVA kernel_name,RVA kernel_table 28 | dd 0,0,0,RVA user_name,RVA user_table 29 | dd 0,0,0,0,0 30 | 31 | kernel_table: 32 | ExitProcess dd RVA _ExitProcess 33 | dd 0 34 | user_table: 35 | MessageBoxA dd RVA _MessageBoxA 36 | dd 0 37 | 38 | kernel_name db 'KERNEL32.DLL',0 39 | user_name db 'USER32.DLL',0 40 | 41 | _ExitProcess dw 0 42 | db 'ExitProcess',0 43 | _MessageBoxA dw 0 44 | db 'MessageBoxA',0 45 | 46 | section '.reloc' fixups data readable discardable ; needed for Win32s 47 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/PE64DEMO/PE64DEMO.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; Example of 64-bit PE program 3 | 4 | format PE64 GUI 5 | entry start 6 | 7 | section '.text' code readable executable 8 | 9 | start: 10 | sub rsp,8*5 ; reserve stack for API use and make stack dqword aligned 11 | 12 | mov r9d,0 13 | lea r8,[_caption] 14 | lea rdx,[_message] 15 | mov rcx,0 16 | call [MessageBoxA] 17 | 18 | mov ecx,eax 19 | call [ExitProcess] 20 | 21 | section '.data' data readable writeable 22 | 23 | _caption db 'Win64 assembly program',0 24 | _message db 'Hello World!',0 25 | 26 | section '.idata' import data readable writeable 27 | 28 | dd 0,0,0,RVA kernel_name,RVA kernel_table 29 | dd 0,0,0,RVA user_name,RVA user_table 30 | dd 0,0,0,0,0 31 | 32 | kernel_table: 33 | ExitProcess dq RVA _ExitProcess 34 | dq 0 35 | user_table: 36 | MessageBoxA dq RVA _MessageBoxA 37 | dq 0 38 | 39 | kernel_name db 'KERNEL32.DLL',0 40 | user_name db 'USER32.DLL',0 41 | 42 | _ExitProcess dw 0 43 | db 'ExitProcess',0 44 | _MessageBoxA dw 0 45 | db 'MessageBoxA',0 46 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/DLL/WRITEMSG.ASM: -------------------------------------------------------------------------------- 1 | format PE64 console DLL 2 | entry DllEntryPoint 3 | 4 | include 'win64a.inc' 5 | 6 | section '.text' code readable executable 7 | 8 | proc DllEntryPoint hinstDLL,fdwReason,lpvReserved 9 | mov eax,TRUE 10 | ret 11 | endp 12 | 13 | proc WriteMessage uses rbx rsi rdi, message 14 | mov rdi,rcx ; first parameter passed in RCX 15 | invoke GetStdHandle,STD_OUTPUT_HANDLE 16 | mov rbx,rax 17 | xor al,al 18 | or rcx,-1 19 | repne scasb 20 | dec rdi 21 | mov r8,-2 22 | sub r8,rcx 23 | sub rdi,r8 24 | invoke WriteFile,rbx,rdi,r8,bytes_count,0 25 | ret 26 | endp 27 | 28 | section '.bss' data readable writeable 29 | 30 | bytes_count dd ? 31 | 32 | section '.edata' export data readable 33 | 34 | export 'WRITEMSG.DLL',\ 35 | WriteMessage,'WriteMessage' 36 | 37 | section '.reloc' fixups data readable discardable 38 | 39 | if $=$$ 40 | dd 0,8 ; if there are no fixups, generate dummy entry 41 | end if 42 | 43 | section '.idata' import data readable writeable 44 | 45 | library kernel32,'KERNEL32.DLL' 46 | 47 | include 'api/kernel32.inc' 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Visit http://flatassembler.net/ for more information. 3 | == 4 | ## Flat assembler 1.73.30 for Windows 5 | 6 | The flat assembler (abbreviated to fasm, intentionally stylized with lowercase letters) is a fast assembler running in a variety of operating systems, in continued development since 1999. 7 | It was designed primarily for the assembly of x86 instructions and it supports x86 and x86-64 instructions sets with extensions like MMX, 3DNow!, SSE up to SSE4, AVX, AVX2, XOP, and AVX-512. 8 | It can produce output in plain binary, MZ, PE, COFF or ELF format. 9 | It includes a powerful but simple macroinstruction system and does multiple passes to optimize the size of instruction codes. 10 | The flat assembler is self-hosting and the complete source code is included. 11 | 12 | The only difference between flat assembler versions included in the following packages is the operating system on which they can be executed. 13 | For any given source text each version is going to generate exactly the same output file, so each of the following releases can be used to compile programs for any operating system. -------------------------------------------------------------------------------- /INCLUDE/MACRO/COM64.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Macroinstructions for interfacing the COM (Component Object Model) classes 3 | 4 | macro cominvk object,proc,[arg] 5 | { common 6 | assert defined object#.com.object ; must be a COM object 7 | macro call dummy 8 | \{ mov rax,[rcx] 9 | call [rax+object#.#proc] \} 10 | fastcall ,[object],arg 11 | purge call } 12 | 13 | macro comcall handle,interface,proc,[arg] 14 | { common 15 | assert defined interface#.com.interface ; must be a COM interface 16 | macro call dummy 17 | \{ mov rax,[rcx] 18 | call [rax+interface#.#proc] \} 19 | fastcall ,handle,arg 20 | purge call } 21 | 22 | macro interface name,[proc] 23 | { common 24 | struc name \{ 25 | match , @struct \\{ define field@struct .,name, \\} 26 | match no, @struct \\{ . dq ? 27 | virtual at 0 28 | forward 29 | .#proc dq ? 30 | common 31 | .\#\\.com.object = name#.com.interface 32 | end virtual \\} \} 33 | virtual at 0 34 | forward 35 | name#.#proc dq ? 36 | common 37 | name#.com.interface = $ shr 3 38 | end virtual } 39 | 40 | -------------------------------------------------------------------------------- /TOOLS/README.TXT: -------------------------------------------------------------------------------- 1 | 2 | This directory contains some tools, which extract various types of information 3 | from the symbolic information file generated by flat assembler, and present 4 | them in a human-readable form. 5 | 6 | The listing tool creates a listing of assembled code - this tool needs to be 7 | executed in the exact configuration, in which the assembly was taking place. 8 | All the source files and the output file aswell must not have been moved or 9 | modified - if any of them was altered before generating the listing, it is 10 | going to contain garbage instead of useful information. For example, if you 11 | assembled the file with the command like: 12 | 13 | fasm example.asm example.exe -s example.fas 14 | 15 | you should generate listing by immediately running this command from the same 16 | directory: 17 | 18 | listing example.fas example.lst 19 | 20 | In addition, the "-a" switch is recommended to use in the case of executable 21 | formats, as it allows to get the run-time addresses for all the assembled code 22 | and data. 23 | 24 | The preprocessed source and symbols dump tools are simpler ones - they only 25 | need the symbolic information file as input and generate proper output text 26 | regardless of the availability of other files. 27 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1255.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1255 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,192h,201Eh,2026h,2020h,2021h,2C6h,2030h,?,2039h,?,?,?,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,2DCh,2122h,?,203Ah,?,?,?,? 12 | dw 0A0h,0A1h,0A2h,0A3h,20AAh,0A5h,0A6h,0A7h,0A8h,0A9h,0D7h,0ABh,0ACh,0ADh,0AEh,0AFh 13 | dw 0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h,0B8h,0B9h,0F7h,0BBh,0BCh,0BDh,0BEh,0BFh 14 | dw 5B0h,5B1h,5B2h,5B3h,5B4h,5B5h,5B6h,5B7h,5B8h,5B9h,?,5BBh,5BCh,5BDh,5BEh,5BFh 15 | dw 5C0h,5C1h,5C2h,5C3h,5F0h,5F1h,5F2h,5F3h,5F4h,?,?,?,?,?,?,? 16 | dw 5D0h,5D1h,5D2h,5D3h,5D4h,5D5h,5D6h,5D7h,5D8h,5D9h,5DAh,5DBh,5DCh,5DDh,5DEh,5DFh 17 | dw 5E0h,5E1h,5E2h,5E3h,5E4h,5E5h,5E6h,5E7h,5E8h,5E9h,5EAh,?,?,200Eh,200Fh,? 18 | end virtual 19 | 20 | macro du [arg] 21 | { local offset,char 22 | offset = $-$$ 23 | du arg 24 | if arg eqtype '' 25 | repeat ($-offset-$$)/2 26 | load char byte from $$+offset+(%-1)*2 27 | if char > 7Fh 28 | load char word from __encoding:char*2 29 | store word char at $$+offset+(%-1)*2 30 | end if 31 | end repeat 32 | end if } 33 | 34 | struc du [args] 35 | { common label . word 36 | du args } 37 | -------------------------------------------------------------------------------- /INCLUDE/API/COMDLG32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; COMDLG32 API calls 3 | 4 | import comdlg32,\ 5 | ChooseColorA,'ChooseColorA',\ 6 | ChooseColorW,'ChooseColorW',\ 7 | ChooseFontA,'ChooseFontA',\ 8 | ChooseFontW,'ChooseFontW',\ 9 | CommDlgExtendedError,'CommDlgExtendedError',\ 10 | FindTextA,'FindTextA',\ 11 | FindTextW,'FindTextW',\ 12 | FormatCharDlgProc,'FormatCharDlgProc',\ 13 | GetFileTitleA,'GetFileTitleA',\ 14 | GetFileTitleW,'GetFileTitleW',\ 15 | GetOpenFileNameA,'GetOpenFileNameA',\ 16 | GetOpenFileNameW,'GetOpenFileNameW',\ 17 | GetSaveFileNameA,'GetSaveFileNameA',\ 18 | GetSaveFileNameW,'GetSaveFileNameW',\ 19 | LoadAlterBitmap,'LoadAlterBitmap',\ 20 | PageSetupDlgA,'PageSetupDlgA',\ 21 | PageSetupDlgW,'PageSetupDlgW',\ 22 | PrintDlgA,'PrintDlgA',\ 23 | PrintDlgW,'PrintDlgW',\ 24 | ReplaceTextA,'ReplaceTextA',\ 25 | ReplaceTextW,'ReplaceTextW',\ 26 | WantArrows,'WantArrows',\ 27 | dwLBSubclass,'dwLBSubclass',\ 28 | dwOKSubclass,'dwOKSubclass' 29 | 30 | api ChooseColor,\ 31 | ChooseFont,\ 32 | FindText,\ 33 | GetFileTitle,\ 34 | GetOpenFileName,\ 35 | GetSaveFileName,\ 36 | PageSetupDlg,\ 37 | PrintDlg,\ 38 | ReplaceText 39 | -------------------------------------------------------------------------------- /TOOLS/WIN32/SYSTEM.INC: -------------------------------------------------------------------------------- 1 | 2 | display_string: 3 | invoke GetStdHandle,[display_handle] 4 | mov edx,eax 5 | mov edi,esi 6 | or ecx,-1 7 | xor al,al 8 | repne scasb 9 | neg ecx 10 | sub ecx,2 11 | invoke WriteFile,edx,esi,ecx,bytes_count,0 12 | retn 13 | alloc: 14 | invoke VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE 15 | or eax,eax 16 | jz allocation_error 17 | clc 18 | retn 19 | allocation_error: 20 | stc 21 | retn 22 | free: 23 | invoke VirtualFree,eax,0,MEM_RELEASE 24 | retn 25 | open: 26 | invoke CreateFile,edx,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0 27 | cmp eax,-1 28 | je file_error 29 | mov ebx,eax 30 | clc 31 | retn 32 | file_error: 33 | stc 34 | retn 35 | create: 36 | invoke CreateFile,edx,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0 37 | cmp eax,-1 38 | je file_error 39 | mov ebx,eax 40 | clc 41 | retn 42 | write: 43 | invoke WriteFile,ebx,edx,ecx,bytes_count,0 44 | or eax,eax 45 | jz file_error 46 | clc 47 | retn 48 | read: 49 | push ecx 50 | invoke ReadFile,ebx,edx,ecx,bytes_count,0 51 | pop edx 52 | or eax,eax 53 | jz file_error 54 | cmp edx,[bytes_count] 55 | jne file_error 56 | clc 57 | retn 58 | close: 59 | invoke CloseHandle,ebx 60 | retn 61 | lseek: 62 | movzx eax,al 63 | invoke SetFilePointer,ebx,edx,0,eax 64 | cmp eax,-1 65 | je file_error 66 | retn 67 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1257.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1257 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,?,201Eh,2026h,2020h,2021h,?,2030h,?,2039h,?,0A8h,2C7h,0B8h 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,?,2122h,?,203Ah,?,0AFh,2DBh,? 12 | dw 0A0h,?,0A2h,0A3h,0A4h,?,0A6h,0A7h,0D8h,0A9h,156h,0ABh,0ACh,0ADh,0AEh,0C6h 13 | dw 0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h,0F8h,0B9h,157h,0BBh,0BCh,0BDh,0BEh,0E6h 14 | dw 104h,12Eh,100h,106h,0C4h,0C5h,118h,112h,10Ch,0C9h,179h,116h,122h,136h,12Ah,13Bh 15 | dw 160h,143h,145h,0D3h,14Ch,0D5h,0D6h,0D7h,172h,141h,15Ah,16Ah,0DCh,17Bh,17Dh,0DFh 16 | dw 105h,12Fh,101h,107h,0E4h,0E5h,119h,113h,10Dh,0E9h,17Ah,117h,123h,137h,12Bh,13Ch 17 | dw 161h,144h,146h,0F3h,14Dh,0F5h,0F6h,0F7h,173h,142h,15Bh,16Bh,0FCh,17Ch,17Eh,2D9h 18 | end virtual 19 | 20 | macro du [arg] 21 | { local offset,char 22 | offset = $-$$ 23 | du arg 24 | if arg eqtype '' 25 | repeat ($-offset-$$)/2 26 | load char byte from $$+offset+(%-1)*2 27 | if char > 7Fh 28 | load char word from __encoding:char*2 29 | store word char at $$+offset+(%-1)*2 30 | end if 31 | end repeat 32 | end if } 33 | 34 | struc du [args] 35 | { common label . word 36 | du args } 37 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1258.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1258 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,192h,201Eh,2026h,2020h,2021h,2C6h,2030h,?,2039h,152h,?,?,? 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,2DCh,2122h,?,203Ah,153h,?,?,178h 12 | dw 0A0h,0A1h,0A2h,0A3h,0A4h,0A5h,0A6h,0A7h,0A8h,0A9h,0AAh,0ABh,0ACh,0ADh,0AEh,0AFh 13 | dw 0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h,0B8h,0B9h,0BAh,0BBh,0BCh,0BDh,0BEh,0BFh 14 | dw 0C0h,0C1h,0C2h,102h,0C4h,0C5h,0C6h,0C7h,0C8h,0C9h,0CAh,0CBh,300h,0CDh,0CEh,0CFh 15 | dw 110h,0D1h,309h,0D3h,0D4h,1A0h,0D6h,0D7h,0D8h,0D9h,0DAh,0DBh,0DCh,1AFh,303h,0DFh 16 | dw 0E0h,0E1h,0E2h,103h,0E4h,0E5h,0E6h,0E7h,0E8h,0E9h,0EAh,0EBh,301h,0EDh,0EEh,0EFh 17 | dw 111h,0F1h,323h,0F3h,0F4h,1A1h,0F6h,0F7h,0F8h,0F9h,0FAh,0FBh,0FCh,1B0h,20ABh,0FFh 18 | end virtual 19 | 20 | macro du [arg] 21 | { local offset,char 22 | offset = $-$$ 23 | du arg 24 | if arg eqtype '' 25 | repeat ($-offset-$$)/2 26 | load char byte from $$+offset+(%-1)*2 27 | if char > 7Fh 28 | load char word from __encoding:char*2 29 | store word char at $$+offset+(%-1)*2 30 | end if 31 | end repeat 32 | end if } 33 | 34 | struc du [args] 35 | { common label . word 36 | du args } 37 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1250.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1250 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,?,201Ah,?,201Eh,2026h,2020h,2021h,?,2030h,160h,2039h,15Ah,164h,17Dh,179h 11 | dw ?,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,?,2122h,161h,203Ah,15Bh,165h,17Eh,17Ah 12 | dw 0A0h,2C7h,2D8h,141h,0A4h,104h,0A6h,0A7h,0A8h,0A9h,15Eh,0ABh,0ACh,0ADh,0AEh,17Bh 13 | dw 0B0h,0B1h,2DBh,142h,0B4h,0B5h,0B6h,0B7h,0B8h,105h,15Fh,0BBh,13Dh,2DDh,13Eh,17Ch 14 | dw 154h,0C1h,0C2h,102h,0C4h,139h,106h,0C7h,10Ch,0C9h,118h,0CBh,11Ah,0CDh,0CEh,10Eh 15 | dw 110h,143h,147h,0D3h,0D4h,150h,0D6h,0D7h,158h,16Eh,0DAh,170h,0DCh,0DDh,162h,0DFh 16 | dw 155h,0E1h,0E2h,103h,0E4h,13Ah,107h,0E7h,10Dh,0E9h,119h,0EBh,11Bh,0EDh,0EEh,10Fh 17 | dw 111h,144h,148h,0F3h,0F4h,151h,0F6h,0F7h,159h,16Fh,0FAh,171h,0FCh,0FDh,163h,2D9h 18 | end virtual 19 | 20 | macro du [arg] 21 | { local offset,char 22 | offset = $-$$ 23 | du arg 24 | if arg eqtype '' 25 | repeat ($-offset-$$)/2 26 | load char byte from $$+offset+(%-1)*2 27 | if char > 7Fh 28 | load char word from __encoding:char*2 29 | store word char at $$+offset+(%-1)*2 30 | end if 31 | end repeat 32 | end if } 33 | 34 | struc du [args] 35 | { common label . word 36 | du args } 37 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/WIN1256.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Windows 1256 3 | 4 | rept 1 { local ..encoding 5 | __encoding equ ..encoding } 6 | 7 | virtual at 0 8 | __encoding:: 9 | times 80h dw %-1 10 | dw 20ACh,67Eh,201Ah,192h,201Eh,2026h,2020h,2021h,2C6h,2030h,679h,2039h,152h,686h,698h,688h 11 | dw 6AFh,2018h,2019h,201Ch,201Dh,2022h,2013h,2014h,6A9h,2122h,691h,203Ah,153h,200Ch,200Dh,6BAh 12 | dw 0A0h,60Ch,0A2h,0A3h,0A4h,0A5h,0A6h,0A7h,0A8h,0A9h,6BEh,0ABh,0ACh,0ADh,0AEh,0AFh 13 | dw 0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h,0B8h,0B9h,0BAh,0BBh,0BCh,0BDh,0BEh,0BFh 14 | dw 6C1h,621h,622h,623h,624h,625h,626h,627h,628h,629h,62Ah,62Bh,62Ch,62Dh,62Eh,62Fh 15 | dw 630h,631h,632h,633h,634h,635h,636h,0D7h,637h,638h,639h,63Ah,640h,641h,642h,643h 16 | dw 0E0h,644h,0E2h,645h,646h,647h,648h,0E7h,0E8h,0E9h,0EAh,0EBh,649h,64Ah,0EEh,0EFh 17 | dw 64Bh,64Ch,64Dh,64Eh,0F4h,64Fh,650h,0F7h,651h,0F9h,652h,0FBh,0FCh,200Eh,200Fh,6D2h 18 | end virtual 19 | 20 | macro du [arg] 21 | { local offset,char 22 | offset = $-$$ 23 | du arg 24 | if arg eqtype '' 25 | repeat ($-offset-$$)/2 26 | load char byte from $$+offset+(%-1)*2 27 | if char > 7Fh 28 | load char word from __encoding:char*2 29 | store word char at $$+offset+(%-1)*2 30 | end if 31 | end repeat 32 | end if } 33 | 34 | struc du [args] 35 | { common label . word 36 | du args } 37 | -------------------------------------------------------------------------------- /INCLUDE/MACRO/COM32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Macroinstructions for interfacing the COM (Component Object Model) classes 3 | 4 | macro cominvk object,proc,[arg] 5 | { common 6 | if ~ arg eq 7 | reverse 8 | pushd arg 9 | common 10 | end if 11 | assert defined object#.com.object ; must be a COM object 12 | mov eax,[object] 13 | push eax 14 | mov eax,[eax] 15 | call [eax+object#.#proc] } 16 | 17 | macro comcall handle,interface,proc,[arg] 18 | { common 19 | if ~ arg eq 20 | reverse 21 | pushd arg 22 | common 23 | end if 24 | assert defined interface#.com.interface ; must be a COM interface 25 | if handle eqtype eax | handle eqtype 0 26 | push handle 27 | local ..handle 28 | label ..handle at handle 29 | mov eax,[..handle] 30 | else 31 | mov eax,handle 32 | push eax 33 | mov eax,[eax] 34 | end if 35 | call [eax+interface#.#proc] } 36 | 37 | macro interface name,[proc] 38 | { common 39 | struc name \{ 40 | match , @struct \\{ define field@struct .,name, \\} 41 | match no, @struct \\{ . dd ? 42 | virtual at 0 43 | forward 44 | .#proc dd ? 45 | common 46 | .\#\\.com.object = name#.com.interface 47 | end virtual \\} \} 48 | virtual at 0 49 | forward 50 | name#.#proc dd ? 51 | common 52 | name#.com.interface = $ shr 2 53 | end virtual } 54 | -------------------------------------------------------------------------------- /EXAMPLES/DLL/ERRORMSG.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; DLL creation example 3 | 4 | format PE GUI 4.0 DLL 5 | entry DllEntryPoint 6 | 7 | include 'win32a.inc' 8 | 9 | section '.text' code readable executable 10 | 11 | proc DllEntryPoint hinstDLL,fdwReason,lpvReserved 12 | mov eax,TRUE 13 | ret 14 | endp 15 | 16 | ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); 17 | 18 | proc ShowErrorMessage hWnd,dwError 19 | local lpBuffer:DWORD 20 | lea eax,[lpBuffer] 21 | invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 22 | invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK 23 | invoke LocalFree,[lpBuffer] 24 | ret 25 | endp 26 | 27 | ; VOID ShowLastError(HWND hWnd); 28 | 29 | proc ShowLastError hWnd 30 | invoke GetLastError 31 | stdcall ShowErrorMessage,[hWnd],eax 32 | ret 33 | endp 34 | 35 | section '.idata' import data readable writeable 36 | 37 | library kernel,'KERNEL32.DLL',\ 38 | user,'USER32.DLL' 39 | 40 | import kernel,\ 41 | GetLastError,'GetLastError',\ 42 | SetLastError,'SetLastError',\ 43 | FormatMessage,'FormatMessageA',\ 44 | LocalFree,'LocalFree' 45 | 46 | import user,\ 47 | MessageBox,'MessageBoxA' 48 | 49 | section '.edata' export data readable 50 | 51 | export 'ERRORMSG.DLL',\ 52 | ShowErrorMessage,'ShowErrorMessage',\ 53 | ShowLastError,'ShowLastError' 54 | 55 | section '.reloc' fixups data readable discardable 56 | 57 | if $=$$ 58 | dd 0,8 ; if there are no fixups, generate dummy entry 59 | end if 60 | -------------------------------------------------------------------------------- /INCLUDE/MACRO/IMPORT32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Macroinstructions for making import section 3 | 4 | macro library [name,string] 5 | { common 6 | import.data: 7 | forward 8 | local _label 9 | if defined name#.redundant 10 | if ~ name#.redundant 11 | dd RVA name#.lookup,0,0,RVA _label,RVA name#.address 12 | end if 13 | end if 14 | name#.referred = 1 15 | common 16 | dd 0,0,0,0,0 17 | forward 18 | if defined name#.redundant 19 | if ~ name#.redundant 20 | _label db string,0 21 | rb RVA $ and 1 22 | end if 23 | end if } 24 | 25 | macro import name,[label,string] 26 | { common 27 | rb (- rva $) and 3 28 | if defined name#.referred 29 | name#.lookup: 30 | forward 31 | if used label 32 | if string eqtype '' 33 | local _label 34 | dd RVA _label 35 | else 36 | dd 80000000h + string 37 | end if 38 | end if 39 | common 40 | if $ > name#.lookup 41 | name#.redundant = 0 42 | dd 0 43 | else 44 | name#.redundant = 1 45 | end if 46 | name#.address: 47 | forward 48 | if used label 49 | if string eqtype '' 50 | label dd RVA _label 51 | else 52 | label dd 80000000h + string 53 | end if 54 | end if 55 | common 56 | if ~ name#.redundant 57 | dd 0 58 | end if 59 | forward 60 | if used label & string eqtype '' 61 | _label dw 0 62 | db string,0 63 | rb RVA $ and 1 64 | end if 65 | common 66 | end if } 67 | 68 | macro api [name] {} 69 | -------------------------------------------------------------------------------- /INCLUDE/MACRO/IMPORT64.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Macroinstructions for making import section (64-bit) 3 | 4 | macro library [name,string] 5 | { common 6 | import.data: 7 | forward 8 | local _label 9 | if defined name#.redundant 10 | if ~ name#.redundant 11 | dd RVA name#.lookup,0,0,RVA _label,RVA name#.address 12 | end if 13 | end if 14 | name#.referred = 1 15 | common 16 | dd 0,0,0,0,0 17 | forward 18 | if defined name#.redundant 19 | if ~ name#.redundant 20 | _label db string,0 21 | rb RVA $ and 1 22 | end if 23 | end if } 24 | 25 | macro import name,[label,string] 26 | { common 27 | rb (- rva $) and 7 28 | if defined name#.referred 29 | name#.lookup: 30 | forward 31 | if used label 32 | if string eqtype '' 33 | local _label 34 | dq RVA _label 35 | else 36 | dq 8000000000000000h + string 37 | end if 38 | end if 39 | common 40 | if $ > name#.lookup 41 | name#.redundant = 0 42 | dq 0 43 | else 44 | name#.redundant = 1 45 | end if 46 | name#.address: 47 | forward 48 | if used label 49 | if string eqtype '' 50 | label dq RVA _label 51 | else 52 | label dq 8000000000000000h + string 53 | end if 54 | end if 55 | common 56 | if ~ name#.redundant 57 | dq 0 58 | end if 59 | forward 60 | if used label & string eqtype '' 61 | _label dw 0 62 | db string,0 63 | rb RVA $ and 1 64 | end if 65 | common 66 | end if } 67 | 68 | macro api [name] {} 69 | -------------------------------------------------------------------------------- /INCLUDE/MACRO/EXPORT.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Macroinstruction for making export section 3 | 4 | macro export dllname,[label,string] 5 | { common 6 | local module,addresses,names,ordinal,count 7 | count = 0 8 | forward 9 | count = count+1 10 | common 11 | dd 0,0,0,RVA module,1 12 | dd count,count,RVA addresses,RVA names,RVA ordinal 13 | addresses: 14 | forward 15 | dd RVA label 16 | common 17 | names: 18 | forward 19 | local name 20 | dd RVA name 21 | common 22 | ordinal: count = 0 23 | forward 24 | dw count 25 | count = count+1 26 | common 27 | module db dllname,0 28 | forward 29 | name db string,0 30 | common 31 | local x,y,z,str1,str2,v1,v2 32 | x = count shr 1 33 | while x > 0 34 | y = x 35 | while y < count 36 | z = y 37 | while z-x >= 0 38 | load v1 dword from names+z*4 39 | str1=($-RVA $)+v1 40 | load v2 dword from names+(z-x)*4 41 | str2=($-RVA $)+v2 42 | while v1 > 0 43 | load v1 from str1+%-1 44 | load v2 from str2+%-1 45 | if v1 <> v2 46 | break 47 | end if 48 | end while 49 | if v1 ',0Dh,0Ah 81 | db 0 82 | _error_prefix db 'error: ',0 83 | _error_suffix db '.',0Dh,0Ah,0 84 | 85 | section '.bss' writeable align 4 86 | 87 | argc dd ? 88 | argv dd ? 89 | 90 | display_handle dd ? 91 | character db ? 92 | 93 | params rb 1000h 94 | buffer rb 1000h 95 | -------------------------------------------------------------------------------- /INCLUDE/PCOUNT/SHELL32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; SHELL32 API calls parameters' count 3 | 4 | CheckEscapes% = 2 5 | DoEnvironmentSubst% = 2 6 | DragAcceptFiles% = 2 7 | DragFinish% = 1 8 | DragQueryFile% = 4 9 | DragQueryPoint% = 2 10 | DuplicateIcon% = 2 11 | ExtractAssociatedIcon% = 3 12 | ExtractAssociatedIconEx% = 4 13 | ExtractIcon% = 3 14 | ExtractIconEx% = 5 15 | ExtractIconResInfo% = 5 16 | FindExeDlgProc% = 4 17 | FindExecutable% = 3 18 | FreeIconList% = 2 19 | InternalExtractIconList% = 3 20 | RealShellExecute% = 10 21 | RealShellExecuteEx% = 11 22 | RegenerateUserEnvironment% = 2 23 | SHAddToRecentDocs% = 2 24 | SHAppBarMessage% = 2 25 | SHBrowseForFolder% = 1 26 | SHChangeNotify% = 4 27 | SHEmptyRecycleBin% = 3 28 | SHFileOperation% = 1 29 | SHFormatDrive% = 4 30 | SHFreeNameMappings% = 1 31 | SHGetDataFromIDList% = 5 32 | SHGetDesktopFolder% = 1 33 | SHGetDiskFreeSpace% = 4 34 | SHGetFileInfo% = 5 35 | SHGetInstanceExplorer% = 1 36 | SHGetMalloc% = 1 37 | SHGetNewLinkInfo% = 5 38 | SHGetPathFromIDList% = 2 39 | SHGetSettings% = 2 40 | SHGetSpecialFolderLocation% = 3 41 | SHGetSpecialFolderPath% = 4 42 | SHInvokePrinterCommand% = 5 43 | SHLoadInProc% = 1 44 | SHQueryRecycleBin% = 2 45 | SHUpdateRecycleBinIcon% = 0 46 | SheChangeDir% = 1 47 | SheChangeDirEx% = 1 48 | SheFullPath% = 3 49 | SheGetCurDrive% = 0 50 | SheGetDir% = 2 51 | SheRemoveQuotes% = 1 52 | SheSetCurDrive% = 1 53 | SheShortenPath% = 2 54 | ShellAbout% = 4 55 | ShellExecute% = 6 56 | ShellExecuteEx% = 1 57 | ShellHookProc% = 3 58 | Shell_NotifyIcon% = 2 59 | StrChr% = 2 60 | StrChrI% = 2 61 | StrCmpN% = 3 62 | StrCmpNI% = 3 63 | StrCpyN% = 3 64 | StrNCmp% = 3 65 | StrNCmpI% = 3 66 | StrNCpy% = 3 67 | StrRChr% = 3 68 | StrRChrI% = 3 69 | StrRStr% = 3 70 | StrRStrI% = 3 71 | StrStr% = 2 72 | StrStrI% = 2 73 | WOWShellExecute% = 7 74 | -------------------------------------------------------------------------------- /TOOLS/LIBC/SYMBOLS.ASM: -------------------------------------------------------------------------------- 1 | 2 | format ELF 3 | public main 4 | 5 | include 'ccall.inc' 6 | 7 | section '.text' executable align 16 8 | 9 | main: 10 | mov ecx,[esp+4] 11 | mov [argc],ecx 12 | mov ebx,[esp+8] 13 | mov [argv],ebx 14 | 15 | mov [display_handle],1 16 | 17 | call get_params 18 | jnc make_dump 19 | 20 | mov esi,_usage 21 | call display_string 22 | ccall exit,2 23 | 24 | make_dump: 25 | call symbols 26 | ccall exit,0 27 | 28 | error: 29 | mov [display_handle],2 30 | mov esi,_error_prefix 31 | call display_string 32 | pop esi 33 | call display_string 34 | mov esi,_error_suffix 35 | call display_string 36 | ccall exit,0 37 | 38 | get_params: 39 | mov ecx,[argc] 40 | mov ebx,[argv] 41 | add ebx,4 42 | dec ecx 43 | jz bad_params 44 | get_param: 45 | mov esi,[ebx] 46 | mov al,[esi] 47 | cmp [input_file],0 48 | jne get_output_file 49 | mov [input_file],esi 50 | jmp next_param 51 | get_output_file: 52 | cmp [output_file],0 53 | jne bad_params 54 | mov [output_file],esi 55 | jmp next_param 56 | bad_params: 57 | stc 58 | ret 59 | next_param: 60 | add ebx,4 61 | dec ecx 62 | jnz get_param 63 | cmp [input_file],0 64 | je bad_params 65 | cmp [output_file],0 66 | je bad_params 67 | clc 68 | ret 69 | 70 | include 'system.inc' 71 | 72 | include '..\symbols.inc' 73 | 74 | section '.data' writeable align 4 75 | 76 | input_file dd 0 77 | output_file dd 0 78 | 79 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 80 | db 'usage: symbols ',0Dh,0Ah 81 | db 0 82 | _error_prefix db 'error: ',0 83 | _error_suffix db '.',0Dh,0Ah,0 84 | 85 | section '.bss' writeable align 4 86 | 87 | input dd ? 88 | output_buffer dd ? 89 | output_handle dd ? 90 | 91 | argc dd ? 92 | argv dd ? 93 | 94 | display_handle dd ? 95 | character db ? 96 | 97 | params rb 1000h 98 | buffer rb 1000h 99 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/WIN64AVX/WIN64AVX.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE64 NX GUI 6.0 3 | entry start 4 | 5 | include 'win64a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _title db 'AVX playground',0 10 | _error db 'AVX instructions are not supported.',0 11 | 12 | x dq 3.14159265389 13 | 14 | vector_output: 15 | rept 16 i:0 16 | { 17 | db 'ymm',`i,': %f,%f,%f,%f',13,10 18 | } 19 | db 0 20 | 21 | buffer db 1000h dup ? 22 | 23 | section '.text' code readable executable 24 | 25 | start: 26 | 27 | mov eax,1 28 | cpuid 29 | and ecx,18000000h 30 | cmp ecx,18000000h 31 | jne no_AVX 32 | xor ecx,ecx 33 | xgetbv 34 | and eax,110b 35 | cmp eax,110b 36 | jne no_AVX 37 | 38 | vbroadcastsd ymm0, [x] 39 | vsqrtpd ymm1, ymm0 40 | 41 | vsubpd ymm2, ymm0, ymm1 42 | vsubpd ymm3, ymm1, ymm2 43 | 44 | vaddpd xmm4, xmm2, xmm3 45 | vaddpd ymm5, ymm4, ymm0 46 | 47 | vperm2f128 ymm6, ymm4, ymm5, 03h 48 | vshufpd ymm7, ymm6, ymm5, 10010011b 49 | 50 | vroundpd ymm8, ymm7, 0011b 51 | vroundpd ymm9, ymm7, 0 52 | 53 | sub rsp,418h 54 | 55 | rept 16 i:0 56 | { 57 | vmovups [rsp+10h+i*32],ymm#i 58 | } 59 | 60 | mov r8,[rsp+10h] 61 | mov r9,[rsp+18h] 62 | lea rdx,[vector_output] 63 | lea rcx,[buffer] 64 | call [sprintf] 65 | 66 | xor ecx,ecx 67 | lea rdx,[buffer] 68 | lea r8,[_title] 69 | xor r9d,r9d 70 | call [MessageBoxA] 71 | 72 | xor ecx,ecx 73 | call [ExitProcess] 74 | 75 | no_AVX: 76 | 77 | sub rsp,28h 78 | 79 | xor ecx,ecx 80 | lea rdx,[_error] 81 | lea r8,[_title] 82 | mov r9d,10h 83 | call [MessageBoxA] 84 | 85 | mov ecx,1 86 | call [ExitProcess] 87 | 88 | section '.idata' import data readable writeable 89 | 90 | library kernel32,'KERNEL32.DLL',\ 91 | user32,'USER32.DLL',\ 92 | msvcrt,'MSVCRT.DLL' 93 | 94 | include 'api\kernel32.inc' 95 | include 'api\user32.inc' 96 | 97 | import msvcrt,\ 98 | sprintf,'sprintf' 99 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | 2 | flat assembler version 1.73 3 | Copyright (c) 1999-2022, Tomasz Grysztar. 4 | All rights reserved. 5 | 6 | This program is free for commercial and non-commercial use as long as 7 | the following conditions are adhered to. 8 | 9 | Copyright remains Tomasz Grysztar, and as such any Copyright notices 10 | in the code are not to be removed. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are 14 | met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, 17 | this list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | The licence and distribution terms for any publically available 35 | version or derivative of this code cannot be changed. i.e. this code 36 | cannot simply be copied and put under another distribution licence 37 | (including the GNU Public Licence). 38 | -------------------------------------------------------------------------------- /SOURCE/IDE/FASMW/FEDIT.ASH: -------------------------------------------------------------------------------- 1 | 2 | ; flat editor mode flags 3 | 4 | FEMODE_OVERWRITE = 1 5 | FEMODE_VERTICALSEL = 2 6 | FEMODE_NOUNDO = 4 7 | FEMODE_READONLY = 8 8 | 9 | ; flat editor search flags 10 | 11 | FEFIND_CASESENSITIVE = 1 12 | FEFIND_WHOLEWORDS = 2 13 | FEFIND_BACKWARD = 4 14 | FEFIND_INWHOLETEXT = 8 15 | 16 | ; flat editor styles 17 | 18 | FES_AUTOINDENT = 0001h 19 | FES_AUTOBRACKETS = 0002h 20 | FES_SMARTTABS = 0004h 21 | FES_SECURESEL = 0008h 22 | FES_OPTIMALFILL = 0010h 23 | FES_CONSOLECARET = 0020h 24 | FES_REVIVEDEADKEYS = 0040h 25 | FES_TIMESCROLL = 0080h 26 | 27 | ; flat editor messages 28 | 29 | FEM_SETMODE = WM_USER + 0 30 | FEM_GETMODE = WM_USER + 1 31 | FEM_SETPOS = WM_USER + 2 32 | FEM_GETPOS = WM_USER + 3 33 | FEM_SETSYNTAXHIGHLIGHT = WM_USER + 4 34 | FEM_SETRIGHTCLICKMENU = WM_USER + 5 35 | FEM_SETTEXTCOLOR = WM_USER + 6 36 | FEM_SETSELCOLOR = WM_USER + 7 37 | FEM_FINDFIRST = WM_USER + 8 38 | FEM_FINDNEXT = WM_USER + 9 39 | FEM_CANFINDNEXT = WM_USER + 10 40 | FEM_GETLINELENGTH = WM_USER + 11 41 | FEM_GETLINE = WM_USER + 12 42 | FEM_GETWORDATCARET = WM_USER + 13 43 | FEM_BEGINOPERATION = WM_USER + 14 44 | FEM_ENDOPERATION = WM_USER + 15 45 | FEM_MARKUNMODIFIED = WM_USER + 16 46 | FEM_ISUNMODIFIED = WM_USER + 17 47 | FEM_GETSEARCHTEXT = WM_USER + 18 48 | FEM_GETSEARCHFLAGS = WM_USER + 19 49 | FEM_RELEASESEARCH = WM_USER + 20 50 | FEM_REDO = WM_USER + 84 51 | FEM_CANREDO = WM_USER + 85 52 | 53 | ; flat editor notifications 54 | 55 | FEN_SETFOCUS = 01h 56 | FEN_KILLFOCUS = 02h 57 | FEN_TEXTCHANGE = 03h 58 | FEN_POSCHANGE = 04h 59 | FEN_MODECHANGE = 05h 60 | FEN_OUTOFMEMORY = 0Fh 61 | 62 | ; flat editor position structure 63 | 64 | struct FEPOS 65 | selectionPosition dd ? 66 | selectionLine dd ? 67 | caretPosition dd ? 68 | caretLine dd ? 69 | ends 70 | -------------------------------------------------------------------------------- /SOURCE/VERSION.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler version 1.73 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | ; 6 | ; This programs is free for commercial and non-commercial use as long as 7 | ; the following conditions are adhered to. 8 | ; 9 | ; Redistribution and use in source and binary forms, with or without 10 | ; modification, are permitted provided that the following conditions are 11 | ; met: 12 | ; 13 | ; 1. Redistributions of source code must retain the above copyright notice, 14 | ; this list of conditions and the following disclaimer. 15 | ; 2. Redistributions in binary form must reproduce the above copyright 16 | ; notice, this list of conditions and the following disclaimer in the 17 | ; documentation and/or other materials provided with the distribution. 18 | ; 19 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | ; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | ; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 23 | ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | ; 31 | ; The licence and distribution terms for any publically available 32 | ; version or derivative of this code cannot be changed. i.e. this code 33 | ; cannot simply be copied and put under another distribution licence 34 | ; (including the GNU Public Licence). 35 | 36 | VERSION_STRING equ "1.73.30" 37 | 38 | VERSION_MAJOR = 1 39 | VERSION_MINOR = 73 40 | -------------------------------------------------------------------------------- /SOURCE/IDE/VERSION.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat editor version 3.12 3 | ; Copyright (c) 1999-2015, Tomasz Grysztar. 4 | ; All rights reserved. 5 | ; 6 | ; This programs is free for commercial and non-commercial use as long as 7 | ; the following conditions are adhered to. 8 | ; 9 | ; Redistribution and use in source and binary forms, with or without 10 | ; modification, are permitted provided that the following conditions are 11 | ; met: 12 | ; 13 | ; 1. Redistributions of source code must retain the above copyright notice, 14 | ; this list of conditions and the following disclaimer. 15 | ; 2. Redistributions in binary form must reproduce the above copyright 16 | ; notice, this list of conditions and the following disclaimer in the 17 | ; documentation and/or other materials provided with the distribution. 18 | ; 19 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | ; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | ; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 23 | ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | ; 31 | ; The licence and distribution terms for any publically available 32 | ; version or derivative of this code cannot be changed. i.e. this code 33 | ; cannot simply be copied and put under another distribution licence 34 | ; (including the GNU Public Licence). 35 | 36 | FEDIT_VERSION_STRING equ "3.12" 37 | 38 | FEDIT_VERSION_MAJOR = 3 39 | FEDIT_VERSION_MINOR = 12 40 | -------------------------------------------------------------------------------- /INCLUDE/PCOUNT/COMCTL32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; COMCTL32 API calls parameters' count 3 | 4 | CreateMappedBitmap% = 5 5 | CreatePropertySheetPage% = 1 6 | CreateStatusWindow% = 4 7 | CreateToolbar% = 8 8 | CreateToolbarEx% = 13 9 | CreateUpDownControl% = 12 10 | DestroyPropertySheetPage% = 1 11 | DrawInsert% = 3 12 | DrawStatusText% = 4 13 | FlatSB_EnableScrollBar% = 3 14 | FlatSB_GetScrollInfo% = 3 15 | FlatSB_GetScrollPos% = 2 16 | FlatSB_GetScrollProp% = 3 17 | FlatSB_GetScrollRange% = 4 18 | FlatSB_SetScrollInfo% = 4 19 | FlatSB_SetScrollPos% = 4 20 | FlatSB_SetScrollProp% = 4 21 | FlatSB_SetScrollRange% = 5 22 | FlatSB_ShowScrollBar% = 3 23 | GetEffectiveClientRect% = 3 24 | ImageList_Add% = 3 25 | ImageList_AddIcon% = 2 26 | ImageList_AddMasked% = 3 27 | ImageList_BeginDrag% = 4 28 | ImageList_Copy% = 5 29 | ImageList_Create% = 5 30 | ImageList_Destroy% = 1 31 | ImageList_DragEnter% = 3 32 | ImageList_DragLeave% = 1 33 | ImageList_DragMove% = 2 34 | ImageList_DragShowNolock% = 1 35 | ImageList_Draw% = 6 36 | ImageList_DrawEx% = 10 37 | ImageList_DrawIndirect% = 1 38 | ImageList_Duplicate% = 1 39 | ImageList_EndDrag% = 0 40 | ImageList_GetBkColor% = 1 41 | ImageList_GetDragImage% = 2 42 | ImageList_GetIcon% = 3 43 | ImageList_GetIconSize% = 3 44 | ImageList_GetImageCount% = 1 45 | ImageList_GetImageInfo% = 3 46 | ImageList_GetImageRect% = 3 47 | ImageList_LoadImage% = 7 48 | ImageList_Merge% = 6 49 | ImageList_Read% = 1 50 | ImageList_Remove% = 2 51 | ImageList_Replace% = 4 52 | ImageList_ReplaceIcon% = 3 53 | ImageList_SetBkColor% = 2 54 | ImageList_SetDragCursorImage% = 4 55 | ImageList_SetFilter% = 3 56 | ImageList_SetIconSize% = 3 57 | ImageList_SetImageCount% = 2 58 | ImageList_SetOverlayImage% = 3 59 | ImageList_Write% = 2 60 | InitCommonControls% = 0 61 | InitCommonControlsEx% = 1 62 | InitializeFlatSB% = 1 63 | LBItemFromPt% = 4 64 | MakeDragList% = 1 65 | MenuHelp% = 7 66 | PropertySheet% = 1 67 | ShowHideMenuCtl% = 3 68 | UninitializeFlatSB% = 1 69 | _TrackMouseEvent% = 1 70 | -------------------------------------------------------------------------------- /TOOLS/LIBC/SYSTEM.INC: -------------------------------------------------------------------------------- 1 | 2 | extrn malloc 3 | extrn getenv 4 | extrn fopen 5 | extrn fclose 6 | extrn fread 7 | extrn fwrite 8 | extrn fseek 9 | extrn ftell 10 | extrn time 11 | extrn exit 12 | extrn 'free' as libc_free 13 | extrn 'write' as libc_write 14 | 15 | alloc: 16 | ccall malloc,eax 17 | test eax,eax 18 | jz allocation_failed 19 | clc 20 | ret 21 | allocation_failed: 22 | stc 23 | ret 24 | free: 25 | ccall libc_free,eax 26 | ret 27 | display_string: 28 | lodsb 29 | or al,al 30 | jz string_displayed 31 | mov dl,al 32 | call display_character 33 | jmp display_string 34 | string_displayed: 35 | ret 36 | display_character: 37 | mov [character],dl 38 | ccall libc_write,[display_handle],character,1 39 | ret 40 | open: 41 | push esi edi ebp 42 | call adapt_path 43 | ccall fopen,buffer,open_mode 44 | pop ebp edi esi 45 | or eax,eax 46 | jz file_error 47 | mov ebx,eax 48 | clc 49 | ret 50 | adapt_path: 51 | mov esi,edx 52 | mov edi,buffer 53 | copy_path: 54 | lods byte [esi] 55 | cmp al,'\' 56 | jne path_char_ok 57 | mov al,'/' 58 | path_char_ok: 59 | stos byte [edi] 60 | or al,al 61 | jnz copy_path 62 | cmp edi,buffer+1000h 63 | ja not_enough_memory 64 | ret 65 | create: 66 | push esi edi ebp 67 | call adapt_path 68 | ccall fopen,buffer,create_mode 69 | pop ebp edi esi 70 | or eax,eax 71 | jz file_error 72 | mov ebx,eax 73 | clc 74 | ret 75 | close: 76 | ccall fclose,ebx 77 | ret 78 | read: 79 | push ebx ecx edx esi edi 80 | ccall fread,edx,1,ecx,ebx 81 | pop edi esi edx ecx ebx 82 | cmp eax,ecx 83 | jne file_error 84 | clc 85 | ret 86 | file_error: 87 | stc 88 | ret 89 | write: 90 | push ebx ecx edx esi edi 91 | ccall fwrite,edx,1,ecx,ebx 92 | pop edi esi edx ecx ebx 93 | cmp eax,ecx 94 | jne file_error 95 | clc 96 | ret 97 | lseek: 98 | push ebx 99 | movzx eax,al 100 | ccall fseek,ebx,edx,eax 101 | mov ebx,[esp] 102 | ccall ftell,ebx 103 | pop ebx 104 | ret 105 | 106 | open_mode db 'r',0 107 | create_mode db 'w',0 108 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/TEMPLATE/TEMPLATE.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE64 GUI 5.0 3 | entry start 4 | 5 | include 'win64a.inc' 6 | 7 | section '.text' code readable executable 8 | 9 | start: 10 | sub rsp,8 ; Make stack dqword aligned 11 | 12 | invoke GetModuleHandle,0 13 | mov [wc.hInstance],rax 14 | invoke LoadIcon,0,IDI_APPLICATION 15 | mov [wc.hIcon],rax 16 | mov [wc.hIconSm],rax 17 | invoke LoadCursor,0,IDC_ARROW 18 | mov [wc.hCursor],rax 19 | invoke RegisterClassEx,wc 20 | test rax,rax 21 | jz error 22 | 23 | invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL 24 | test rax,rax 25 | jz error 26 | 27 | msg_loop: 28 | invoke GetMessage,msg,NULL,0,0 29 | cmp eax,1 30 | jb end_loop 31 | jne msg_loop 32 | invoke TranslateMessage,msg 33 | invoke DispatchMessage,msg 34 | jmp msg_loop 35 | 36 | error: 37 | invoke MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK 38 | 39 | end_loop: 40 | invoke ExitProcess,[msg.wParam] 41 | 42 | proc WindowProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam 43 | 44 | ; Note that first four parameters are passed in registers, 45 | ; while names given in the declaration of procedure refer to the stack 46 | ; space reserved for them - you may store them there to be later accessible 47 | ; if the contents of registers gets destroyed. This may look like: 48 | ; mov [hwnd],rcx 49 | ; mov [wmsg],edx 50 | ; mov [wparam],r8 51 | ; mov [lparam],r9 52 | 53 | cmp edx,WM_DESTROY 54 | je .wmdestroy 55 | .defwndproc: 56 | invoke DefWindowProc,rcx,rdx,r8,r9 57 | jmp .finish 58 | .wmdestroy: 59 | invoke PostQuitMessage,0 60 | xor eax,eax 61 | .finish: 62 | ret 63 | 64 | endp 65 | 66 | section '.data' data readable writeable 67 | 68 | _title TCHAR 'Win64 program template',0 69 | _class TCHAR 'FASMWIN64',0 70 | _error TCHAR 'Startup failed.',0 71 | 72 | wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class,NULL 73 | 74 | msg MSG 75 | 76 | section '.idata' import data readable writeable 77 | 78 | library kernel32,'KERNEL32.DLL',\ 79 | user32,'USER32.DLL' 80 | 81 | include 'api\kernel32.inc' 82 | include 'api\user32.inc' 83 | -------------------------------------------------------------------------------- /INCLUDE/MACRO/MASM.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Simulate MASM's syntax 3 | 4 | struc struct 5 | { struct . 6 | name@struct equ . } 7 | 8 | struc ends 9 | { match =.,name@struct \{ ends \} } 10 | 11 | struc proc [params] 12 | { common define@proc ., 13 | name@proc equ . } 14 | 15 | struc endp 16 | { match =.,name@proc \{ endp \} } 17 | 18 | macro option setting 19 | { match =prologue:macro, setting \{ prologue@proc equ macro \} 20 | match =epilogue:macro, setting \{ epilogue@proc equ macro \} } 21 | 22 | macro none procname,flag,parmbytes,localbytes,reglist { } 23 | 24 | macro assume params 25 | { 26 | local expr 27 | define expr params 28 | match reg:struct, expr 29 | \{ 30 | match assumed, reg\#@assumed \\{ irp name, assumed \\\{ restore name \\\} \\} 31 | macro label . \\{ local def 32 | define def . 33 | match =reg =at label, def \\\{ define def \\\} 34 | match name at,def \\\{ def@assumed reg,name,label at 35 | define def \\\} 36 | match name,def \\\{ def@assumed reg,.,: \\\} \\} 37 | struc db [val] \\{ \common def@assumed reg,., \\} 38 | struc dw [val] \\{ \common def@assumed reg,., \\} 39 | struc dp [val] \\{ \common def@assumed reg,., \\} 40 | struc dd [val] \\{ \common def@assumed reg,.,
\\} 41 | struc dt [val] \\{ \common def@assumed reg,.,
\\} 42 | struc dq [val] \\{ \common def@assumed reg,., \\} 43 | struc rb cnt \\{ def@assumed reg,.,rb cnt \\} 44 | struc rw cnt \\{ def@assumed reg,.,rw cnt \\} 45 | struc rp cnt \\{ def@assumed reg,.,rp cnt \\} 46 | struc rd cnt \\{ def@assumed reg,.,rd cnt \\} 47 | struc rt cnt \\{ def@assumed reg,.,rt cnt \\} 48 | struc rq cnt \\{ def@assumed reg,.,rq cnt \\} 49 | reg\#@assumed equ 50 | virtual at reg 51 | reg struct 52 | end virtual 53 | purge label 54 | restruc db,dw,dp,dd,dt,dq 55 | restruc rb,rw,rp,rd,rt,rq \} } 56 | 57 | macro def@assumed reg,name,def 58 | { match vars, reg#@assumed \{ reg#@assumed equ reg#@assumed, \} 59 | reg#@assumed equ reg#@assumed name 60 | local ..label 61 | name equ ..label 62 | ..label def } 63 | 64 | struc label type { label . type } 65 | 66 | struc none { label . } 67 | -------------------------------------------------------------------------------- /TOOLS/DOS/LOADER.INC: -------------------------------------------------------------------------------- 1 | 2 | segment loader use16 3 | 4 | init: 5 | 6 | mov ax,1687h 7 | int 2Fh 8 | or ax,ax ; DPMI installed? 9 | jnz short no_dpmi 10 | test bl,1 ; 32-bit programs supported? 11 | jz short no_dpmi 12 | mov word [cs:mode_switch],di 13 | mov word [cs:mode_switch+2],es 14 | mov bx,si ; allocate memory for DPMI data 15 | mov ah,48h 16 | int 21h 17 | jnc init_protected_mode 18 | init_failed: 19 | call init_error 20 | db 'error: DPMI initialization failed.',0Dh,0Ah,0 21 | no_dpmi: 22 | call init_error 23 | db 'error: 32-bit DPMI services are not available.',0Dh,0Ah,0 24 | init_error: 25 | pop si 26 | push cs 27 | pop ds 28 | display_error: 29 | lodsb 30 | test al,al 31 | jz short error_finish 32 | mov dl,al 33 | mov ah,2 34 | int 21h 35 | jmp short display_error 36 | error_finish: 37 | mov ax,4CFFh 38 | int 21h 39 | init_protected_mode: 40 | mov es,ax 41 | mov ds,[ds:2Ch] 42 | mov ax,1 43 | call far [cs:mode_switch] ; switch to protected mode 44 | jc init_failed 45 | mov cx,1 46 | xor ax,ax 47 | int 31h ; allocate descriptor for code 48 | jc init_failed 49 | mov si,ax 50 | xor ax,ax 51 | int 31h ; allocate descriptor for data 52 | jc init_failed 53 | mov di,ax 54 | mov dx,cs 55 | lar cx,dx 56 | shr cx,8 57 | or cx,0C000h 58 | mov bx,si 59 | mov ax,9 60 | int 31h ; set code descriptor access rights 61 | jc init_failed 62 | mov dx,ds 63 | lar cx,dx 64 | shr cx,8 65 | or cx,0C000h 66 | mov bx,di 67 | int 31h ; set data descriptor access rights 68 | jc init_failed 69 | mov ecx,main 70 | shl ecx,4 71 | mov dx,cx 72 | shr ecx,16 73 | mov ax,7 74 | int 31h ; set data descriptor base address 75 | jc init_failed 76 | mov bx,si 77 | int 31h ; set code descriptor base address 78 | jc init_failed 79 | mov cx,0FFFFh 80 | mov dx,0FFFFh 81 | mov ax,8 ; set segment limit to 4 GB 82 | int 31h 83 | jc init_failed 84 | mov bx,di 85 | int 31h 86 | jc init_failed 87 | mov ax,ds 88 | mov ds,di 89 | mov [psp_selector],es 90 | mov [environment_selector],ax 91 | cli 92 | mov ss,di 93 | mov esp,stack_top 94 | sti 95 | mov es,di 96 | xor eax,eax 97 | mov [memory_handles_count],eax 98 | push si 99 | push start 100 | retf 101 | 102 | mode_switch dd ? 103 | -------------------------------------------------------------------------------- /TOOLS/PREPSRC.INC: -------------------------------------------------------------------------------- 1 | 2 | preprocessed_source: 3 | mov edx,[input_file] 4 | call open 5 | jc input_not_found 6 | mov al,2 7 | xor edx,edx 8 | call lseek 9 | cmp eax,30h 10 | jb invalid_input 11 | push eax 12 | call alloc 13 | jc not_enough_memory 14 | push eax 15 | xor al,al 16 | xor edx,edx 17 | call lseek 18 | mov ecx,[esp+4] 19 | mov edx,[esp] 20 | call read 21 | jc reading_error 22 | pop eax ecx 23 | cmp dword [eax],1A736166h 24 | jne invalid_input 25 | mov esi,[eax+32] 26 | add esi,eax 27 | mov ebp,[eax+36] 28 | add ebp,esi 29 | mov edi,eax 30 | push eax 31 | preprocessed_to_text: 32 | cmp esi,ebp 33 | jae conversion_done 34 | add esi,16 35 | xor dl,dl 36 | convert_preprocessed_line: 37 | lodsb 38 | cmp al,1Ah 39 | je copy_symbol 40 | cmp al,22h 41 | je copy_symbol 42 | cmp al,3Bh 43 | je preprocessor_symbols 44 | or al,al 45 | jz line_converted 46 | stosb 47 | xor dl,dl 48 | jmp convert_preprocessed_line 49 | copy_symbol: 50 | or dl,dl 51 | jz space_ok 52 | mov byte [edi],20h 53 | inc edi 54 | space_ok: 55 | cmp al,22h 56 | je quoted 57 | lodsb 58 | movzx ecx,al 59 | rep movsb 60 | or dl,-1 61 | jmp convert_preprocessed_line 62 | quoted: 63 | mov al,27h 64 | stosb 65 | lodsd 66 | mov ecx,eax 67 | jecxz quoted_copied 68 | copy_quoted: 69 | lodsb 70 | stosb 71 | cmp al,27h 72 | jne quote_ok 73 | stosb 74 | quote_ok: 75 | loop copy_quoted 76 | quoted_copied: 77 | mov al,27h 78 | stosb 79 | or dl,-1 80 | jmp convert_preprocessed_line 81 | preprocessor_symbols: 82 | mov al,3Bh 83 | stosb 84 | jmp copy_symbol 85 | line_converted: 86 | mov ax,0A0Dh 87 | stosw 88 | jmp preprocessed_to_text 89 | conversion_done: 90 | mov edx,[output_file] 91 | call create 92 | jc writing_error 93 | pop edx 94 | mov ecx,edi 95 | sub ecx,edx 96 | call write 97 | jc writing_error 98 | call close 99 | ret 100 | 101 | not_enough_memory: 102 | call error 103 | db 'not enough memory to load the required data',0 104 | input_not_found: 105 | call error 106 | db 'the input file was not found',0 107 | reading_error: 108 | call error 109 | db 'some error occured while trying to read file',0 110 | writing_error: 111 | call error 112 | db 'some error occured while trying to write file',0 113 | invalid_input: 114 | call error 115 | db 'input file is not a recognized assembly information format',0 116 | -------------------------------------------------------------------------------- /SOURCE/DOS/DPMI.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for DOS 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | init_dpmi_memory: 7 | mov ax,500h ; get free memory information 8 | mov edi,[buffer_address] 9 | int 31h 10 | mov ebx,[edi] 11 | allocate_dpmi_memory: 12 | mov edx,[memory_setting] 13 | shl edx,10 14 | jz dpmi_memory_size_ok 15 | cmp ebx,edx 16 | jbe dpmi_memory_size_ok 17 | mov ebx,edx 18 | dpmi_memory_size_ok: 19 | mov [memory_end],ebx 20 | mov ecx,ebx 21 | shr ebx,16 22 | mov ax,501h 23 | int 31h 24 | jnc dpmi_memory_ok 25 | mov ebx,[memory_end] 26 | shr ebx,1 27 | cmp ebx,4000h 28 | jb out_of_memory 29 | jmp allocate_dpmi_memory 30 | dpmi_memory_ok: 31 | shl ebx,16 32 | mov bx,cx 33 | sub ebx,[program_base] 34 | jc out_of_memory 35 | mov [memory_start],ebx 36 | add [memory_end],ebx 37 | mov ax,100h ; get free conventional memory size 38 | mov bx,-1 39 | int 31h 40 | movzx ecx,bx 41 | shl ecx,4 42 | jecxz no_conventional_memory 43 | mov ax,100h ; allocate all conventional memory 44 | int 31h 45 | movzx edi,ax 46 | shl edi,4 47 | sub edi,[program_base] 48 | jc no_conventional_memory 49 | mov [additional_memory],edi 50 | mov [additional_memory_end],edi 51 | add [additional_memory_end],ecx 52 | mov eax,[memory_end] 53 | sub eax,[memory_start] 54 | shr eax,2 55 | cmp eax,ecx 56 | ja no_conventional_memory 57 | ret 58 | no_conventional_memory: 59 | mov eax,[memory_end] 60 | mov ebx,[memory_start] 61 | sub eax,ebx 62 | shr eax,2 63 | mov [additional_memory],ebx 64 | add ebx,eax 65 | mov [additional_memory_end],ebx 66 | mov [memory_start],ebx 67 | ret 68 | 69 | dpmi_dos_int: 70 | mov [real_mode_segment],main 71 | simulate_real_mode: 72 | push 0 ; SS:SP (DPMI will allocate stack) 73 | push 0 ; CS:IP (ignored) 74 | push 0 75 | push [real_mode_segment] ; DS 76 | push [real_mode_segment] ; ES 77 | stc 78 | pushfw 79 | push eax 80 | push ecx 81 | push edx 82 | push ebx 83 | push 0 84 | push ebp 85 | push esi 86 | push edi 87 | mov ax,300h 88 | mov bx,21h 89 | xor cx,cx 90 | mov edi,esp 91 | push es ss 92 | pop es 93 | int 31h 94 | pop es 95 | mov edi,[esp] 96 | mov esi,[esp+4] 97 | mov ebp,[esp+8] 98 | mov ebx,[esp+10h] 99 | mov edx,[esp+14h] 100 | mov ecx,[esp+18h] 101 | mov ah,[esp+20h] 102 | sahf 103 | mov eax,[esp+1Ch] 104 | lea esp,[esp+32h] 105 | ret 106 | dpmi_dos_int_with_buffer: 107 | mov [real_mode_segment],buffer 108 | jmp simulate_real_mode 109 | -------------------------------------------------------------------------------- /SOURCE/MESSAGES.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | _out_of_memory db 'out of memory',0 7 | _stack_overflow db 'out of stack space',0 8 | _main_file_not_found db 'source file not found',0 9 | _code_cannot_be_generated db 'code cannot be generated',0 10 | _format_limitations_exceeded db 'format limitations exceeded',0 11 | _invalid_definition db 'invalid definition provided',0 12 | _write_failed db 'write failed',0 13 | _file_not_found db 'file not found',0 14 | _error_reading_file db 'error reading file',0 15 | _invalid_file_format db 'invalid file format',0 16 | _invalid_macro_arguments db 'invalid macro arguments',0 17 | _incomplete_macro db 'incomplete macro',0 18 | _unexpected_characters db 'unexpected characters',0 19 | _invalid_argument db 'invalid argument',0 20 | _illegal_instruction db 'illegal instruction',0 21 | _invalid_operand db 'invalid operand',0 22 | _invalid_operand_size db 'invalid size of operand',0 23 | _operand_size_not_specified db 'operand size not specified',0 24 | _operand_sizes_do_not_match db 'operand sizes do not match',0 25 | _invalid_address_size db 'invalid size of address value',0 26 | _address_sizes_do_not_agree db 'address sizes do not agree',0 27 | _disallowed_combination_of_registers db 'disallowed combination of registers',0 28 | _long_immediate_not_encodable db 'not encodable with long immediate',0 29 | _relative_jump_out_of_range db 'relative jump out of range',0 30 | _invalid_expression db 'invalid expression',0 31 | _invalid_address db 'invalid address',0 32 | _invalid_value db 'invalid value',0 33 | _value_out_of_range db 'value out of range',0 34 | _undefined_symbol db 'undefined symbol',0 35 | _symbol_out_of_scope_1 db 'symbol',0 36 | _symbol_out_of_scope_2 db 'out of scope',0 37 | _invalid_use_of_symbol db 'invalid use of symbol',0 38 | _name_too_long db 'name too long',0 39 | _invalid_name db 'invalid name',0 40 | _reserved_word_used_as_symbol db 'reserved word used as symbol',0 41 | _symbol_already_defined db 'symbol already defined',0 42 | _missing_end_quote db 'missing end quote',0 43 | _missing_end_directive db 'missing end directive',0 44 | _unexpected_instruction db 'unexpected instruction',0 45 | _extra_characters_on_line db 'extra characters on line',0 46 | _section_not_aligned_enough db 'section is not aligned enough',0 47 | _setting_already_specified db 'setting already specified',0 48 | _data_already_defined db 'data already defined',0 49 | _too_many_repeats db 'too many repeats',0 50 | _invoked_error db 'error directive encountered in source file',0 51 | _assertion_failed db 'assertion failed',0 52 | -------------------------------------------------------------------------------- /INCLUDE/ENCODING/UTF8.INC: -------------------------------------------------------------------------------- 1 | 2 | ; UTF-8 3 | 4 | macro du [arg] 5 | { local current,..input,char 6 | if arg eqtype '' 7 | virtual at 0 8 | ..input:: 9 | db arg 10 | count = $ 11 | end virtual 12 | current = 0 13 | while current < count 14 | load char byte from ..input:current 15 | wide = char 16 | current = current + 1 17 | if char > 0C0h 18 | if char < 0E0h 19 | wide = char and 11111b 20 | load char byte from ..input:current 21 | wide = wide shl 6 + (char and 111111b) 22 | current = current + 1 23 | else if char < 0F0h 24 | wide = char and 1111b 25 | load char byte from ..input:current 26 | wide = wide shl 6 + (char and 111111b) 27 | load char byte from ..input:current+1 28 | wide = wide shl 6 + (char and 111111b) 29 | current = current + 2 30 | else if char < 0F8h 31 | wide = char and 111b 32 | load char byte from ..input:current 33 | wide = wide shl 6 + (char and 111111b) 34 | load char byte from ..input:current+1 35 | wide = wide shl 6 + (char and 111111b) 36 | load char byte from ..input:current+2 37 | wide = wide shl 6 + (char and 111111b) 38 | current = current + 3 39 | else if char < 0FCh 40 | wide = char and 11b 41 | load char byte from ..input:current 42 | wide = wide shl 6 + (char and 111111b) 43 | load char byte from ..input:current+1 44 | wide = wide shl 6 + (char and 111111b) 45 | load char byte from ..input:current+2 46 | wide = wide shl 6 + (char and 111111b) 47 | load char byte from ..input:current+3 48 | wide = wide shl 6 + (char and 111111b) 49 | current = current + 4 50 | else 51 | wide = char and 1 52 | load char byte from ..input:current 53 | wide = wide shl 6 + (char and 111111b) 54 | load char byte from ..input:current+1 55 | wide = wide shl 6 + (char and 111111b) 56 | load char byte from ..input:current+2 57 | wide = wide shl 6 + (char and 111111b) 58 | load char byte from ..input:current+3 59 | wide = wide shl 6 + (char and 111111b) 60 | load char byte from ..input:current+4 61 | wide = wide shl 6 + (char and 111111b) 62 | current = current + 5 63 | end if 64 | end if 65 | if wide < 10000h 66 | dw wide 67 | else 68 | dw 0D7C0h + wide shr 10,0DC00h or (wide and 3FFh) 69 | end if 70 | end while 71 | else 72 | dw arg 73 | end if } 74 | 75 | struc du [args] 76 | { common label . word 77 | du args } 78 | -------------------------------------------------------------------------------- /TOOLS/DOS/PREPSRC.ASM: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_dump 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_dump: 22 | call preprocessed_source 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,0Dh 46 | je all_params 47 | or al,al 48 | jz all_params 49 | cmp [es:input_file],0 50 | jne get_output_file 51 | mov [es:input_file],edi 52 | jmp process_param 53 | get_output_file: 54 | cmp [es:output_file],0 55 | jne bad_params 56 | mov [es:output_file],edi 57 | process_param: 58 | cmp al,22h 59 | je string_param 60 | copy_param: 61 | stosb 62 | lodsb 63 | cmp al,20h 64 | je param_end 65 | cmp al,0Dh 66 | je param_end 67 | or al,al 68 | jz param_end 69 | jmp copy_param 70 | string_param: 71 | lodsb 72 | cmp al,22h 73 | je string_param_end 74 | cmp al,0Dh 75 | je param_end 76 | or al,al 77 | jz param_end 78 | stosb 79 | jmp string_param 80 | bad_params_value: 81 | stc 82 | ret 83 | param_end: 84 | dec esi 85 | string_param_end: 86 | xor al,al 87 | stosb 88 | jmp find_param 89 | all_params: 90 | xor al,al 91 | stosb 92 | pop ds 93 | cmp [input_file],0 94 | je bad_params 95 | cmp [output_file],0 96 | je bad_params 97 | clc 98 | ret 99 | bad_params: 100 | stc 101 | ret 102 | 103 | include 'system.inc' 104 | 105 | include '..\prepsrc.inc' 106 | 107 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah 108 | db 'usage: prepsrc ',0Dh,0Ah 109 | db 0 110 | _error_prefix db 'error: ',0 111 | _error_suffix db '.',0Dh,0Ah,0 112 | 113 | input_file dd 0 114 | output_file dd 0 115 | 116 | psp_selector dw ? 117 | environment_selector dw ? 118 | 119 | memory_handles_count dd ? 120 | memory_handles rd 400h 121 | 122 | params rb 1000h 123 | 124 | segment buffer_segment 125 | 126 | buffer = (buffer_segment-main) shl 4 127 | 128 | db 1000h dup ? 129 | 130 | segment stack_segment 131 | 132 | stack_bottom = (stack_segment-main) shl 4 133 | 134 | db 4000h dup ? 135 | 136 | stack_top = stack_bottom + $ 137 | -------------------------------------------------------------------------------- /TOOLS/DOS/SYMBOLS.ASM: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_dump 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_dump: 22 | call symbols 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,0Dh 46 | je all_params 47 | or al,al 48 | jz all_params 49 | cmp [es:input_file],0 50 | jne get_output_file 51 | mov [es:input_file],edi 52 | jmp process_param 53 | get_output_file: 54 | cmp [es:output_file],0 55 | jne bad_params 56 | mov [es:output_file],edi 57 | process_param: 58 | cmp al,22h 59 | je string_param 60 | copy_param: 61 | stosb 62 | lodsb 63 | cmp al,20h 64 | je param_end 65 | cmp al,0Dh 66 | je param_end 67 | or al,al 68 | jz param_end 69 | jmp copy_param 70 | string_param: 71 | lodsb 72 | cmp al,22h 73 | je string_param_end 74 | cmp al,0Dh 75 | je param_end 76 | or al,al 77 | jz param_end 78 | stosb 79 | jmp string_param 80 | bad_params_value: 81 | stc 82 | ret 83 | param_end: 84 | dec esi 85 | string_param_end: 86 | xor al,al 87 | stosb 88 | jmp find_param 89 | all_params: 90 | xor al,al 91 | stosb 92 | pop ds 93 | cmp [input_file],0 94 | je bad_params 95 | cmp [output_file],0 96 | je bad_params 97 | clc 98 | ret 99 | bad_params: 100 | stc 101 | ret 102 | 103 | include 'system.inc' 104 | 105 | include '..\symbols.inc' 106 | 107 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 108 | db 'usage: symbols ',0Dh,0Ah 109 | db 0 110 | _error_prefix db 'error: ',0 111 | _error_suffix db '.',0Dh,0Ah,0 112 | 113 | input_file dd 0 114 | output_file dd 0 115 | 116 | input dd ? 117 | output_buffer dd ? 118 | output_handle dd ? 119 | 120 | psp_selector dw ? 121 | environment_selector dw ? 122 | 123 | memory_handles_count dd ? 124 | memory_handles rd 400h 125 | 126 | params rb 1000h 127 | 128 | segment buffer_segment 129 | 130 | buffer = (buffer_segment-main) shl 4 131 | 132 | db 1000h dup ? 133 | 134 | segment stack_segment 135 | 136 | stack_bottom = (stack_segment-main) shl 4 137 | 138 | db 4000h dup ? 139 | 140 | stack_top = stack_bottom + $ 141 | -------------------------------------------------------------------------------- /INCLUDE/EQUATES/WSOCK32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; WSOCK32.DLL structures and constants 3 | 4 | struct WSADATA 5 | wVersion dw ? 6 | wHighVersion dw ? 7 | szDescription db 256+1 dup (?) 8 | szSystemStatus db 128+1 dup (?) 9 | iMaxSockets dw ? 10 | iMaxUdpDg dw ? 11 | _padding_ db 2 dup (?) 12 | lpVendorInfo dd ? 13 | ends 14 | 15 | struct hostent 16 | h_name dd ? 17 | h_aliases dd ? 18 | h_addrtype dw ? 19 | h_length dw ? 20 | h_addr_list dd ? 21 | ends 22 | 23 | struct sockaddr_in 24 | sin_family dw ? 25 | sin_port dw ? 26 | sin_addr dd ? 27 | sin_zero db 8 dup (?) 28 | ends 29 | 30 | struct sockaddr 31 | sa_family dw ? 32 | sa_data db 14 dup (?) 33 | ends 34 | 35 | ; Socket types 36 | 37 | SOCK_STREAM = 1 38 | SOCK_DGRAM = 2 39 | SOCK_RAW = 3 40 | SOCK_RDM = 4 41 | SOCK_SEQPACKET = 5 42 | 43 | ; Address formats 44 | 45 | AF_UNSPEC = 0 46 | AF_UNIX = 1 47 | AF_INET = 2 48 | AF_IMPLINK = 3 49 | AF_PUP = 4 50 | AF_CHAOS = 5 51 | AF_NS = 6 52 | AF_IPX = 6 53 | AF_ISO = 7 54 | AF_OSI = AF_ISO 55 | AF_ECMA = 8 56 | AF_DATAKIT = 9 57 | AF_CCITT = 10 58 | AF_SNA = 11 59 | AF_DECnet = 12 60 | AF_DLI = 13 61 | AF_LAT = 14 62 | AF_HYLINK = 15 63 | AF_APPLETALK = 16 64 | AF_NETBIOS = 17 65 | 66 | ; Protocol formats 67 | 68 | PF_UNSPEC = 0 69 | PF_UNIX = 1 70 | PF_INET = 2 71 | PF_IMPLINK = 3 72 | PF_PUP = 4 73 | PF_CHAOS = 5 74 | PF_NS = 6 75 | PF_IPX = 6 76 | PF_ISO = 7 77 | PF_OSI = PF_ISO 78 | PF_ECMA = 8 79 | PF_DATAKIT = 9 80 | PF_CCITT = 10 81 | PF_SNA = 11 82 | PF_DECnet = 12 83 | PF_DLI = 13 84 | PF_LAT = 14 85 | PF_HYLINK = 15 86 | PF_APPLETALK = 16 87 | PF_NETBIOS = 17 88 | 89 | ; IP Ports 90 | 91 | IPPORT_ECHO = 7 92 | IPPORT_DISCARD = 9 93 | IPPORT_SYSTAT = 11 94 | IPPORT_DAYTIME = 13 95 | IPPORT_NETSTAT = 15 96 | IPPORT_FTP = 21 97 | IPPORT_TELNET = 23 98 | IPPORT_SMTP = 25 99 | IPPORT_TIMESERVER = 37 100 | IPPORT_NAMESERVER = 42 101 | IPPORT_WHOIS = 43 102 | IPPORT_MTP = 57 103 | IPPORT_TFTP = 69 104 | IPPORT_RJE = 77 105 | IPPORT_FINGER = 79 106 | IPPORT_TTYLINK = 87 107 | IPPORT_SUPDUP = 95 108 | IPPORT_EXECSERVER = 512 109 | IPPORT_LOGINSERVER = 513 110 | IPPORT_CMDSERVER = 514 111 | IPPORT_EFSSERVER = 520 112 | IPPORT_BIFFUDP = 512 113 | IPPORT_WHOSERVER = 513 114 | IPPORT_ROUTESERVER = 520 115 | IPPORT_RESERVED = 1024 116 | 117 | ; Notifications 118 | 119 | FD_READ = 01h 120 | FD_WRITE = 02h 121 | FD_OOB = 04h 122 | FD_ACCEPT = 08h 123 | FD_CONNECT = 10h 124 | FD_CLOSE = 20h 125 | -------------------------------------------------------------------------------- /TOOLS/WIN32/PREPSRC.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah 10 | db 'usage: prepsrc ',0Dh,0Ah 11 | db 0 12 | _error_prefix db 'error: ',0 13 | _error_suffix db '.',0Dh,0Ah,0 14 | 15 | input_file dd 0 16 | output_file dd 0 17 | 18 | display_handle dd ? 19 | bytes_count dd ? 20 | 21 | params rb 1000h 22 | 23 | section '.text' code readable executable 24 | 25 | start: 26 | 27 | mov [display_handle],STD_OUTPUT_HANDLE 28 | 29 | call get_params 30 | jnc make_dump 31 | 32 | mov esi,_usage 33 | call display_string 34 | invoke ExitProcess,2 35 | 36 | make_dump: 37 | call preprocessed_source 38 | invoke ExitProcess,0 39 | 40 | error: 41 | mov [display_handle],STD_ERROR_HANDLE 42 | mov esi,_error_prefix 43 | call display_string 44 | pop esi 45 | call display_string 46 | mov esi,_error_suffix 47 | call display_string 48 | invoke ExitProcess,1 49 | 50 | get_params: 51 | invoke GetCommandLine 52 | mov esi,eax 53 | mov edi,params 54 | find_command_start: 55 | lodsb 56 | cmp al,20h 57 | je find_command_start 58 | cmp al,22h 59 | je skip_quoted_name 60 | skip_name: 61 | lodsb 62 | cmp al,20h 63 | je find_param 64 | or al,al 65 | jz all_params 66 | jmp skip_name 67 | skip_quoted_name: 68 | lodsb 69 | cmp al,22h 70 | je find_param 71 | or al,al 72 | jz all_params 73 | jmp skip_quoted_name 74 | find_param: 75 | lodsb 76 | cmp al,20h 77 | je find_param 78 | cmp al,0Dh 79 | je all_params 80 | or al,al 81 | jz all_params 82 | cmp [input_file],0 83 | jne get_output_file 84 | mov [input_file],edi 85 | jmp process_param 86 | get_output_file: 87 | cmp [output_file],0 88 | jne bad_params 89 | mov [output_file],edi 90 | process_param: 91 | cmp al,22h 92 | je string_param 93 | copy_param: 94 | stosb 95 | lodsb 96 | cmp al,20h 97 | je param_end 98 | cmp al,0Dh 99 | je param_end 100 | or al,al 101 | jz param_end 102 | jmp copy_param 103 | string_param: 104 | lodsb 105 | cmp al,22h 106 | je string_param_end 107 | cmp al,0Dh 108 | je param_end 109 | or al,al 110 | jz param_end 111 | stosb 112 | jmp string_param 113 | bad_params: 114 | stc 115 | ret 116 | param_end: 117 | dec esi 118 | string_param_end: 119 | xor al,al 120 | stosb 121 | jmp find_param 122 | all_params: 123 | cmp [input_file],0 124 | je bad_params 125 | cmp [output_file],0 126 | je bad_params 127 | clc 128 | ret 129 | 130 | include 'system.inc' 131 | 132 | include '..\prepsrc.inc' 133 | 134 | section '.idata' import data readable writeable 135 | 136 | library kernel32,'KERNEL32.DLL' 137 | 138 | include 'api\kernel32.inc' 139 | -------------------------------------------------------------------------------- /TOOLS/WIN32/SYMBOLS.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 10 | db 'usage: symbols ',0Dh,0Ah 11 | db 0 12 | _error_prefix db 'error: ',0 13 | _error_suffix db '.',0Dh,0Ah,0 14 | 15 | input_file dd 0 16 | output_file dd 0 17 | 18 | input dd ? 19 | output_buffer dd ? 20 | output_handle dd ? 21 | 22 | display_handle dd ? 23 | bytes_count dd ? 24 | 25 | params rb 1000h 26 | 27 | section '.text' code readable executable 28 | 29 | start: 30 | 31 | mov [display_handle],STD_OUTPUT_HANDLE 32 | 33 | call get_params 34 | jnc make_dump 35 | 36 | mov esi,_usage 37 | call display_string 38 | invoke ExitProcess,2 39 | 40 | make_dump: 41 | call symbols 42 | invoke ExitProcess,0 43 | 44 | error: 45 | mov [display_handle],STD_ERROR_HANDLE 46 | mov esi,_error_prefix 47 | call display_string 48 | pop esi 49 | call display_string 50 | mov esi,_error_suffix 51 | call display_string 52 | invoke ExitProcess,1 53 | 54 | get_params: 55 | invoke GetCommandLine 56 | mov esi,eax 57 | mov edi,params 58 | find_command_start: 59 | lodsb 60 | cmp al,20h 61 | je find_command_start 62 | cmp al,22h 63 | je skip_quoted_name 64 | skip_name: 65 | lodsb 66 | cmp al,20h 67 | je find_param 68 | or al,al 69 | jz all_params 70 | jmp skip_name 71 | skip_quoted_name: 72 | lodsb 73 | cmp al,22h 74 | je find_param 75 | or al,al 76 | jz all_params 77 | jmp skip_quoted_name 78 | find_param: 79 | lodsb 80 | cmp al,20h 81 | je find_param 82 | cmp al,0Dh 83 | je all_params 84 | or al,al 85 | jz all_params 86 | cmp [input_file],0 87 | jne get_output_file 88 | mov [input_file],edi 89 | jmp process_param 90 | get_output_file: 91 | cmp [output_file],0 92 | jne bad_params 93 | mov [output_file],edi 94 | process_param: 95 | cmp al,22h 96 | je string_param 97 | copy_param: 98 | stosb 99 | lodsb 100 | cmp al,20h 101 | je param_end 102 | cmp al,0Dh 103 | je param_end 104 | or al,al 105 | jz param_end 106 | jmp copy_param 107 | string_param: 108 | lodsb 109 | cmp al,22h 110 | je string_param_end 111 | cmp al,0Dh 112 | je param_end 113 | or al,al 114 | jz param_end 115 | stosb 116 | jmp string_param 117 | bad_params: 118 | stc 119 | ret 120 | param_end: 121 | dec esi 122 | string_param_end: 123 | xor al,al 124 | stosb 125 | jmp find_param 126 | all_params: 127 | cmp [input_file],0 128 | je bad_params 129 | cmp [output_file],0 130 | je bad_params 131 | clc 132 | ret 133 | 134 | include 'system.inc' 135 | 136 | include '..\symbols.inc' 137 | 138 | section '.idata' import data readable writeable 139 | 140 | library kernel32,'KERNEL32.DLL' 141 | 142 | include 'api\kernel32.inc' 143 | -------------------------------------------------------------------------------- /INCLUDE/API/WSOCK32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; WSOCK32 API calls 3 | 4 | import wsock32,\ 5 | AcceptEx,'AcceptEx',\ 6 | EnumProtocolsA,'EnumProtocolsA',\ 7 | EnumProtocolsW,'EnumProtocolsW',\ 8 | GetAcceptExSockaddrs,'GetAcceptExSockaddrs',\ 9 | GetAddressByNameA,'GetAddressByNameA',\ 10 | GetAddressByNameW,'GetAddressByNameW',\ 11 | GetNameByTypeA,'GetNameByTypeA',\ 12 | GetNameByTypeW,'GetNameByTypeW',\ 13 | GetServiceA,'GetServiceA',\ 14 | GetServiceW,'GetServiceW',\ 15 | GetTypeByNameA,'GetTypeByNameA',\ 16 | GetTypeByNameW,'GetTypeByNameW',\ 17 | MigrateWinsockConfiguration,'MigrateWinsockConfiguration',\ 18 | NPLoadNameSpaces,'NPLoadNameSpaces',\ 19 | SetServiceA,'SetServiceA',\ 20 | SetServiceW,'SetServiceW',\ 21 | TransmitFile,'TransmitFile',\ 22 | WEP,'WEP',\ 23 | WSAAsyncGetHostByAddr,'WSAAsyncGetHostByAddr',\ 24 | WSAAsyncGetHostByName,'WSAAsyncGetHostByName',\ 25 | WSAAsyncGetProtoByName,'WSAAsyncGetProtoByName',\ 26 | WSAAsyncGetProtoByNumber,'WSAAsyncGetProtoByNumber',\ 27 | WSAAsyncGetServByName,'WSAAsyncGetServByName',\ 28 | WSAAsyncGetServByPort,'WSAAsyncGetServByPort',\ 29 | WSAAsyncSelect,'WSAAsyncSelect',\ 30 | WSACancelAsyncRequest,'WSACancelAsyncRequest',\ 31 | WSACancelBlockingCall,'WSACancelBlockingCall',\ 32 | WSACleanup,'WSACleanup',\ 33 | WSAGetLastError,'WSAGetLastError',\ 34 | WSAIsBlocking,'WSAIsBlocking',\ 35 | WSARecvEx,'WSARecvEx',\ 36 | WSASetBlockingHook,'WSASetBlockingHook',\ 37 | WSASetLastError,'WSASetLastError',\ 38 | WSAStartup,'WSAStartup',\ 39 | WSAUnhookBlockingHook,'WSAUnhookBlockingHook',\ 40 | __WSAFDIsSet,'__WSAFDIsSet',\ 41 | accept,'accept',\ 42 | bind,'bind',\ 43 | closesocket,'closesocket',\ 44 | connect,'connect',\ 45 | dn_expand,'dn_expand',\ 46 | gethostbyaddr,'gethostbyaddr',\ 47 | gethostbyname,'gethostbyname',\ 48 | gethostname,'gethostname',\ 49 | getnetbyname,'getnetbyname',\ 50 | getpeername,'getpeername',\ 51 | getprotobyname,'getprotobyname',\ 52 | getprotobynumber,'getprotobynumber',\ 53 | getservbyname,'getservbyname',\ 54 | getservbyport,'getservbyport',\ 55 | getsockname,'getsockname',\ 56 | getsockopt,'getsockopt',\ 57 | htonl,'htonl',\ 58 | htons,'htons',\ 59 | inet_addr,'inet_addr',\ 60 | inet_network,'inet_network',\ 61 | inet_ntoa,'inet_ntoa',\ 62 | ioctlsocket,'ioctlsocket',\ 63 | listen,'listen',\ 64 | ntohl,'ntohl',\ 65 | ntohs,'ntohs',\ 66 | rcmd,'rcmd',\ 67 | recv,'recv',\ 68 | recvfrom,'recvfrom',\ 69 | rexec,'rexec',\ 70 | rresvport,'rresvport',\ 71 | s_perror,'s_perror',\ 72 | select,'select',\ 73 | send,'send',\ 74 | sendto,'sendto',\ 75 | sethostname,'sethostname',\ 76 | setsockopt,'setsockopt',\ 77 | shutdown,'shutdown',\ 78 | socket,'socket' 79 | 80 | api EnumProtocols,\ 81 | GetAddressByName,\ 82 | GetNameByType,\ 83 | GetService,\ 84 | GetTypeByName,\ 85 | SetService 86 | -------------------------------------------------------------------------------- /EXTENSIONS/FASM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class FasmCondition : int 4 | { 5 | OK = 00, 6 | WORKING = 01, 7 | FERROR = 02, 8 | INVALID_PARAMETER = -1, 9 | OUT_OF_MEMORY = -2, 10 | STACK_OVERFLOW = -3, 11 | SOURCE_NOT_FOUND = -4, 12 | UNEXPECTED_END_OF_SOURCE = -5, 13 | CANNOT_GENERATE_CODE = -6, 14 | FORMAT_LIMITATIONS_EXCEDDED = -7, 15 | WRITE_FAILED = -8, 16 | }; 17 | 18 | enum class FasmError : int 19 | { 20 | FILE_NOT_FOUND = -101, 21 | ERROR_READING_FILE = -102, 22 | INVALID_FILE_FORMAT = -103, 23 | INVALID_MACRO_ARGUMENTS = -104, 24 | INCOMPLETE_MACRO = -105, 25 | UNEXPECTED_CHARACTERS = -106, 26 | INVALID_ARGUMENT = -107, 27 | ILLEGAL_INSTRUCTION = -108, 28 | INVALID_OPERAND = -109, 29 | INVALID_OPERAND_SIZE = -110, 30 | OPERAND_SIZE_NOT_SPECIFIED = -111, 31 | OPERAND_SIZES_DO_NOT_MATCH = -112, 32 | INVALID_ADDRESS_SIZE = -113, 33 | ADDRESS_SIZES_DO_NOT_AGREE = -114, 34 | DISALLOWED_COMBINATION_OF_REGISTERS = -115, 35 | LONG_IMMEDIATE_NOT_ENCODABLE = -116, 36 | RELATIVE_JUMP_OUT_OF_RANGE = -117, 37 | INVALID_EXPRESSION = -118, 38 | INVALID_ADDRESS = -119, 39 | INVALID_VALUE = -120, 40 | VALUE_OUT_OF_RANGE = -121, 41 | UNDEFINED_SYMBOL = -122, 42 | INVALID_USE_OF_SYMBOL = -123, 43 | NAME_TOO_LONG = -124, 44 | INVALID_NAME = -125, 45 | RESERVED_WORD_USED_AS_SYMBOL = -126, 46 | SYMBOL_ALREADY_DEFINED = -127, 47 | MISSING_END_QUOTE = -128, 48 | MISSING_END_DIRECTIVE = -129, 49 | UNEXPECTED_INSTRUCTION = -130, 50 | EXTRA_CHARACTERS_ON_LINE = -131, 51 | SECTION_NOT_ALIGNED_ENOUGH = -132, 52 | SETTING_ALREADY_SPECIFIED = -133, 53 | DATA_ALREADY_DEFINED = -134, 54 | TOO_MANY_REPEATS = -135, 55 | SYMBOL_OUT_OF_SCOPE = -136, 56 | USER_ERROR = -140, 57 | ASSERTION_FAILED = -141, 58 | }; 59 | 60 | typedef struct _FasmLineHeader { 61 | char* file_path; 62 | int line_number; 63 | union { 64 | int file_offset; 65 | int macro_offset_line; 66 | }; 67 | _FasmLineHeader* macro_line; 68 | } FASM_LINE_HEADER; 69 | 70 | typedef struct _FasmState { 71 | FasmCondition condition; 72 | union { 73 | FasmError error_code; 74 | int output_length; 75 | }; 76 | union { 77 | __int8* output_data; 78 | _FasmLineHeader* error_data; 79 | }; 80 | } FASM_STATE; 81 | 82 | extern "C" int __cdecl fasm_Assemble(char* szSource, __int8* lpMemory, int nSize, int nPassesLimit, int hDisplayPipe); 83 | extern "C" int __cdecl fasm_GetVersion(); -------------------------------------------------------------------------------- /SOURCE/VARIABLE.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core variables 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | ; Variables which have to be set up by interface: 7 | 8 | memory_start dd ? 9 | memory_end dd ? 10 | 11 | additional_memory dd ? 12 | additional_memory_end dd ? 13 | 14 | stack_limit dd ? 15 | 16 | initial_definitions dd ? 17 | input_file dd ? 18 | output_file dd ? 19 | symbols_file dd ? 20 | 21 | passes_limit dw ? 22 | 23 | ; Internal core variables: 24 | 25 | current_pass dw ? 26 | 27 | include_paths dd ? 28 | free_additional_memory dd ? 29 | source_start dd ? 30 | code_start dd ? 31 | code_size dd ? 32 | real_code_size dd ? 33 | written_size dd ? 34 | headers_size dd ? 35 | 36 | current_line dd ? 37 | macro_line dd ? 38 | macro_block dd ? 39 | macro_block_line dd ? 40 | macro_block_line_number dd ? 41 | macro_symbols dd ? 42 | struc_name dd ? 43 | struc_label dd ? 44 | instant_macro_start dd ? 45 | parameters_end dd ? 46 | default_argument_value dd ? 47 | locals_counter rb 8 48 | current_locals_prefix dd ? 49 | anonymous_reverse dd ? 50 | anonymous_forward dd ? 51 | labels_list dd ? 52 | label_hash dd ? 53 | label_leaf dd ? 54 | hash_tree dd ? 55 | addressing_space dd ? 56 | undefined_data_start dd ? 57 | undefined_data_end dd ? 58 | counter dd ? 59 | counter_limit dd ? 60 | error_info dd ? 61 | error_line dd ? 62 | error dd ? 63 | tagged_blocks dd ? 64 | structures_buffer dd ? 65 | number_start dd ? 66 | current_offset dd ? 67 | value dq ? 68 | fp_value rd 8 69 | adjustment dq ? 70 | symbol_identifier dd ? 71 | address_symbol dd ? 72 | address_high dd ? 73 | uncompressed_displacement dd ? 74 | format_flags dd ? 75 | resolver_flags dd ? 76 | symbols_stream dd ? 77 | number_of_relocations dd ? 78 | number_of_sections dd ? 79 | stub_size dd ? 80 | stub_file dd ? 81 | current_section dd ? 82 | machine dw ? 83 | subsystem dw ? 84 | subsystem_version dd ? 85 | image_base dd ? 86 | image_base_high dd ? 87 | merge_segment dd ? 88 | resource_data dd ? 89 | resource_size dd ? 90 | actual_fixups_size dd ? 91 | reserved_fixups dd ? 92 | reserved_fixups_size dd ? 93 | last_fixup_base dd ? 94 | last_fixup_header dd ? 95 | parenthesis_stack dd ? 96 | blocks_stack dd ? 97 | parsed_lines dd ? 98 | logical_value_parentheses dd ? 99 | file_extension dd ? 100 | 101 | operand_size db ? 102 | operand_flags db ? 103 | operand_prefix db ? 104 | rex_prefix db ? 105 | opcode_prefix db ? 106 | vex_required db ? 107 | vex_register db ? 108 | immediate_size db ? 109 | mask_register db ? 110 | broadcast_size db ? 111 | rounding_mode db ? 112 | 113 | base_code db ? 114 | extended_code db ? 115 | supplemental_code db ? 116 | postbyte_register db ? 117 | segment_register db ? 118 | xop_opcode_map db ? 119 | 120 | mmx_size db ? 121 | jump_type db ? 122 | push_size db ? 123 | value_size db ? 124 | address_size db ? 125 | label_size db ? 126 | size_declared db ? 127 | address_size_declared db ? 128 | displacement_compression db ? 129 | 130 | value_undefined db ? 131 | value_constant db ? 132 | value_type db ? 133 | value_sign db ? 134 | fp_sign db ? 135 | fp_format db ? 136 | address_sign db ? 137 | address_register db ? 138 | compare_type db ? 139 | logical_value_wrapping db ? 140 | next_pass_needed db ? 141 | output_format db ? 142 | code_type db ? 143 | adjustment_sign db ? 144 | evex_mode db ? 145 | 146 | macro_status db ? 147 | skip_default_argument_value db ? 148 | prefix_flags db ? 149 | formatter_symbols_allowed db ? 150 | decorator_symbols_allowed db ? 151 | free_address_range db ? 152 | 153 | characters rb 100h 154 | converted rb 100h 155 | message rb 180h 156 | -------------------------------------------------------------------------------- /INCLUDE/EQUATES/SHELL32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; SHELL32.DLL structures and constants 3 | 4 | struct NOTIFYICONDATA 5 | cbSize dd ? 6 | hWnd dd ? 7 | uID dd ? 8 | uFlags dd ? 9 | uCallbackMessage dd ? 10 | hIcon dd ? 11 | szTip TCHAR 64 dup (?) 12 | ends 13 | 14 | struct NOTIFYICONDATAA 15 | cbSize dd ? 16 | hWnd dd ? 17 | uID dd ? 18 | uFlags dd ? 19 | uCallbackMessage dd ? 20 | hIcon dd ? 21 | szTip db 64 dup (?) 22 | ends 23 | 24 | struct NOTIFYICONDATAW 25 | cbSize dd ? 26 | hWnd dd ? 27 | uID dd ? 28 | uFlags dd ? 29 | uCallbackMessage dd ? 30 | hIcon dd ? 31 | szTip du 64 dup (?) 32 | ends 33 | 34 | struct BROWSEINFO 35 | hwndOwner dd ? 36 | pidlRoot dd ? 37 | pszDisplayName dd ? 38 | lpszTitle dd ? 39 | ulFlags dd ? 40 | lpfn dd ? 41 | lParam dd ? 42 | iImage dd ? 43 | ends 44 | 45 | ; Taskbar icon messages 46 | 47 | NIM_ADD = 0 48 | NIM_MODIFY = 1 49 | NIM_DELETE = 2 50 | NIM_SETFOCUS = 3 51 | NIM_SETVERSION = 4 52 | 53 | ; Taskbar icon flags 54 | 55 | NIF_MESSAGE = 01h 56 | NIF_ICON = 02h 57 | NIF_TIP = 04h 58 | NIF_STATE = 08h 59 | NIF_INFO = 10h 60 | NIF_GUID = 20h 61 | 62 | ; Constant Special Item ID List 63 | 64 | CSIDL_DESKTOP = 0x0000 65 | CSIDL_INTERNET = 0x0001 66 | CSIDL_PROGRAMS = 0x0002 67 | CSIDL_CONTROLS = 0x0003 68 | CSIDL_PRINTERS = 0x0004 69 | CSIDL_PERSONAL = 0x0005 70 | CSIDL_FAVORITES = 0x0006 71 | CSIDL_STARTUP = 0x0007 72 | CSIDL_RECENT = 0x0008 73 | CSIDL_SENDTO = 0x0009 74 | CSIDL_BITBUCKET = 0x000A 75 | CSIDL_STARTMENU = 0x000B 76 | CSIDL_MYDOCUMENTS = 0x000C 77 | CSIDL_MYMUSIC = 0x000D 78 | CSIDL_MYVIDEO = 0x000E 79 | CSIDL_DESKTOPDIRECTORY = 0x0010 80 | CSIDL_DRIVES = 0x0011 81 | CSIDL_NETWORK = 0x0012 82 | CSIDL_NETHOOD = 0x0013 83 | CSIDL_FONTS = 0x0014 84 | CSIDL_TEMPLATES = 0x0015 85 | CSIDL_COMMON_STARTMENU = 0x0016 86 | CSIDL_COMMON_PROGRAMS = 0x0017 87 | CSIDL_COMMON_STARTUP = 0x0018 88 | CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019 89 | CSIDL_APPDATA = 0x001A 90 | CSIDL_PRINTHOOD = 0x001B 91 | CSIDL_LOCAL_APPDATA = 0x001C 92 | CSIDL_ALTSTARTUP = 0x001D 93 | CSIDL_COMMON_ALTSTARTUP = 0x001E 94 | CSIDL_COMMON_FAVORITES = 0x001F 95 | CSIDL_INTERNET_CACHE = 0x0020 96 | CSIDL_COOKIES = 0x0021 97 | CSIDL_HISTORY = 0x0022 98 | CSIDL_COMMON_APPDATA = 0x0023 99 | CSIDL_WINDOWS = 0x0024 100 | CSIDL_SYSTEM = 0x0025 101 | CSIDL_PROGRAM_FILES = 0x0026 102 | CSIDL_MYPICTURES = 0x0027 103 | CSIDL_PROFILE = 0x0028 104 | CSIDL_SYSTEMX86 = 0x0029 105 | CSIDL_PROGRAM_FILESX86 = 0x002A 106 | CSIDL_PROGRAM_FILES_COMMON = 0x002B 107 | CSIDL_PROGRAM_FILES_COMMONX86 = 0x002C 108 | CSIDL_COMMON_TEMPLATES = 0x002D 109 | CSIDL_COMMON_DOCUMENTS = 0x002E 110 | CSIDL_COMMON_ADMINTOOLS = 0x002F 111 | CSIDL_ADMINTOOLS = 0x0030 112 | CSIDL_CONNECTIONS = 0x0031 113 | CSIDL_COMMON_MUSIC = 0x0035 114 | CSIDL_COMMON_PICTURES = 0x0036 115 | CSIDL_COMMON_VIDEO = 0x0037 116 | CSIDL_RESOURCES = 0x0038 117 | CSIDL_RESOURCES_LOCALIZED = 0x0039 118 | CSIDL_COMMON_OEM_LINKS = 0x003A 119 | CSIDL_CDBURN_AREA = 0x003B 120 | CSIDL_COMPUTERSNEARME = 0x003D 121 | CSIDL_PROFILES = 0x003E 122 | CSIDL_FOLDER_MASK = 0x00FF 123 | CSIDL_FLAG_PER_USER_INIT = 0x0800 124 | CSIDL_FLAG_NO_ALIAS = 0x1000 125 | CSIDL_FLAG_DONT_VERIFY = 0x4000 126 | CSIDL_FLAG_CREATE = 0x8000 127 | CSIDL_FLAG_MASK = 0xFF00 128 | -------------------------------------------------------------------------------- /INCLUDE/EQUATES/SHELL64.INC: -------------------------------------------------------------------------------- 1 | 2 | ; SHELL32.DLL structures and constants 3 | 4 | struct NOTIFYICONDATA 5 | cbSize dd ?,? 6 | hWnd dq ? 7 | uID dd ? 8 | uFlags dd ? 9 | uCallbackMessage dd ?,? 10 | hIcon dq ? 11 | szTip TCHAR 64 dup (?) 12 | ends 13 | 14 | struct NOTIFYICONDATAA 15 | cbSize dd ?,? 16 | hWnd dq ? 17 | uID dd ? 18 | uFlags dd ? 19 | uCallbackMessage dd ?,? 20 | hIcon dq ? 21 | szTip db 64 dup (?) 22 | ends 23 | 24 | struct NOTIFYICONDATAW 25 | cbSize dd ?,? 26 | hWnd dq ? 27 | uID dd ? 28 | uFlags dd ? 29 | uCallbackMessage dd ?,? 30 | hIcon dq ? 31 | szTip du 64 dup (?) 32 | ends 33 | 34 | struct BROWSEINFO 35 | hwndOwner dq ? 36 | pidlRoot dq ? 37 | pszDisplayName dq ? 38 | lpszTitle dq ? 39 | ulFlags dd ?,? 40 | lpfn dq ? 41 | lParam dq ? 42 | iImage dq ? 43 | ends 44 | 45 | ; Taskbar icon messages 46 | 47 | NIM_ADD = 0 48 | NIM_MODIFY = 1 49 | NIM_DELETE = 2 50 | NIM_SETFOCUS = 3 51 | NIM_SETVERSION = 4 52 | 53 | ; Taskbar icon flags 54 | 55 | NIF_MESSAGE = 01h 56 | NIF_ICON = 02h 57 | NIF_TIP = 04h 58 | NIF_STATE = 08h 59 | NIF_INFO = 10h 60 | NIF_GUID = 20h 61 | 62 | ; Constant Special Item ID List 63 | 64 | CSIDL_DESKTOP = 0x0000 65 | CSIDL_INTERNET = 0x0001 66 | CSIDL_PROGRAMS = 0x0002 67 | CSIDL_CONTROLS = 0x0003 68 | CSIDL_PRINTERS = 0x0004 69 | CSIDL_PERSONAL = 0x0005 70 | CSIDL_FAVORITES = 0x0006 71 | CSIDL_STARTUP = 0x0007 72 | CSIDL_RECENT = 0x0008 73 | CSIDL_SENDTO = 0x0009 74 | CSIDL_BITBUCKET = 0x000A 75 | CSIDL_STARTMENU = 0x000B 76 | CSIDL_MYDOCUMENTS = 0x000C 77 | CSIDL_MYMUSIC = 0x000D 78 | CSIDL_MYVIDEO = 0x000E 79 | CSIDL_DESKTOPDIRECTORY = 0x0010 80 | CSIDL_DRIVES = 0x0011 81 | CSIDL_NETWORK = 0x0012 82 | CSIDL_NETHOOD = 0x0013 83 | CSIDL_FONTS = 0x0014 84 | CSIDL_TEMPLATES = 0x0015 85 | CSIDL_COMMON_STARTMENU = 0x0016 86 | CSIDL_COMMON_PROGRAMS = 0x0017 87 | CSIDL_COMMON_STARTUP = 0x0018 88 | CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019 89 | CSIDL_APPDATA = 0x001A 90 | CSIDL_PRINTHOOD = 0x001B 91 | CSIDL_LOCAL_APPDATA = 0x001C 92 | CSIDL_ALTSTARTUP = 0x001D 93 | CSIDL_COMMON_ALTSTARTUP = 0x001E 94 | CSIDL_COMMON_FAVORITES = 0x001F 95 | CSIDL_INTERNET_CACHE = 0x0020 96 | CSIDL_COOKIES = 0x0021 97 | CSIDL_HISTORY = 0x0022 98 | CSIDL_COMMON_APPDATA = 0x0023 99 | CSIDL_WINDOWS = 0x0024 100 | CSIDL_SYSTEM = 0x0025 101 | CSIDL_PROGRAM_FILES = 0x0026 102 | CSIDL_MYPICTURES = 0x0027 103 | CSIDL_PROFILE = 0x0028 104 | CSIDL_SYSTEMX86 = 0x0029 105 | CSIDL_PROGRAM_FILESX86 = 0x002A 106 | CSIDL_PROGRAM_FILES_COMMON = 0x002B 107 | CSIDL_PROGRAM_FILES_COMMONX86 = 0x002C 108 | CSIDL_COMMON_TEMPLATES = 0x002D 109 | CSIDL_COMMON_DOCUMENTS = 0x002E 110 | CSIDL_COMMON_ADMINTOOLS = 0x002F 111 | CSIDL_ADMINTOOLS = 0x0030 112 | CSIDL_CONNECTIONS = 0x0031 113 | CSIDL_COMMON_MUSIC = 0x0035 114 | CSIDL_COMMON_PICTURES = 0x0036 115 | CSIDL_COMMON_VIDEO = 0x0037 116 | CSIDL_RESOURCES = 0x0038 117 | CSIDL_RESOURCES_LOCALIZED = 0x0039 118 | CSIDL_COMMON_OEM_LINKS = 0x003A 119 | CSIDL_CDBURN_AREA = 0x003B 120 | CSIDL_COMPUTERSNEARME = 0x003D 121 | CSIDL_PROFILES = 0x003E 122 | CSIDL_FOLDER_MASK = 0x00FF 123 | CSIDL_FLAG_PER_USER_INIT = 0x0800 124 | CSIDL_FLAG_NO_ALIAS = 0x1000 125 | CSIDL_FLAG_DONT_VERIFY = 0x4000 126 | CSIDL_FLAG_CREATE = 0x8000 127 | CSIDL_FLAG_MASK = 0xFF00 128 | -------------------------------------------------------------------------------- /SOURCE/LINUX/X64/MODES.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Linux x64 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | esp equ +rsp 7 | 8 | macro pushD [arg] 9 | { 10 | common 11 | local offset,total 12 | offset = 0 13 | lea rsp,[rsp-total] 14 | forward 15 | offset = offset + 4 16 | if arg eqtype eax 17 | mov dword [rsp+total-offset],arg 18 | else 19 | mov r8d,dword arg 20 | mov [rsp+total-offset],r8d 21 | end if 22 | common 23 | total = offset 24 | } 25 | 26 | macro popD [arg] 27 | { 28 | common 29 | local offset 30 | offset = 0 31 | forward 32 | if arg eqtype [mem] 33 | mov r8d,[rsp+offset] 34 | mov dword arg,r8d 35 | else 36 | mov arg,dword [rsp+offset] 37 | end if 38 | offset = offset + 4 39 | common 40 | lea rsp,[rsp+offset] 41 | } 42 | 43 | macro add dest,src 44 | { 45 | if dest eq esp 46 | add rsp,src 47 | else 48 | add dest,src 49 | end if 50 | } 51 | 52 | macro mov dest,src 53 | { 54 | if src eq esp 55 | mov dest,ESP 56 | else 57 | mov dest,src 58 | end if 59 | } 60 | 61 | macro cmp dest,src 62 | { 63 | if dest eq esp 64 | cmp ESP,src 65 | else 66 | cmp dest,src 67 | end if 68 | } 69 | 70 | macro use32 71 | { 72 | 73 | macro push args 74 | \{ 75 | local list,arg,status 76 | define list 77 | define arg 78 | irps sym, args \\{ 79 | define status 80 | match =dword, sym \\\{ 81 | define status : 82 | \\\} 83 | match [any, status arg sym \\\{ 84 | define arg [any 85 | match [mem], arg \\\\{ 86 | match previous, list \\\\\{ define list previous,[mem] \\\\\} 87 | match , list \\\\\{ define list [mem] \\\\\} 88 | define arg 89 | \\\\} 90 | define status : 91 | \\\} 92 | match [, status arg sym \\\{ 93 | define arg [ 94 | define status : 95 | \\\} 96 | match , status \\\{ 97 | match previous, list \\\\{ define list previous,sym \\\\} 98 | match , list \\\\{ define list sym \\\\} 99 | \\\} 100 | \\} 101 | match arg, list \\{ pushD arg \\} 102 | \} 103 | 104 | macro pop args 105 | \{ 106 | local list,arg,status 107 | define list 108 | define arg 109 | irps sym, args \\{ 110 | define status 111 | match =dword, sym \\\{ 112 | define status : 113 | \\\} 114 | match [any, status arg sym \\\{ 115 | define arg [any 116 | match [mem], arg \\\\{ 117 | match previous, list \\\\\{ define list previous,[mem] \\\\\} 118 | match , list \\\\\{ define list [mem] \\\\\} 119 | define arg 120 | \\\\} 121 | define status : 122 | \\\} 123 | match [, status arg sym \\\{ 124 | define arg [ 125 | define status : 126 | \\\} 127 | match , status \\\{ 128 | match previous, list \\\\{ define list previous,sym \\\\} 129 | match , list \\\\{ define list sym \\\\} 130 | \\\} 131 | \\} 132 | match arg, list \\{ popD arg \\} 133 | \} 134 | 135 | macro jmp arg 136 | \{ 137 | if arg eq near eax 138 | jmp near rax 139 | else if arg eq near edx 140 | jmp near rdx 141 | else if arg eqtype [mem] 142 | mov r8d,arg 143 | jmp near r8 144 | else 145 | jmp arg 146 | end if 147 | \} 148 | 149 | macro call arg 150 | \{ 151 | if 1 152 | match =near =dword [mem], arg \\{ 153 | mov r8d,[mem] 154 | call near r8 155 | else 156 | \\} 157 | call arg 158 | end if 159 | \} 160 | 161 | macro salc ; for fasm's core it does not need to preserve flags 162 | \{ 163 | setc al 164 | neg al 165 | \} 166 | 167 | macro jcxz target ; for fasm's core it does not need to preserve flags 168 | \{ 169 | test cx,cx 170 | jz target 171 | \} 172 | 173 | use64 174 | 175 | } 176 | 177 | macro use16 178 | { 179 | 180 | purge push,pop,jmp,call,salc,jcxz 181 | 182 | use16 183 | 184 | } 185 | 186 | use32 187 | -------------------------------------------------------------------------------- /TOOLS/LIBC/LISTING.ASM: -------------------------------------------------------------------------------- 1 | 2 | format ELF 3 | public main 4 | 5 | include 'ccall.inc' 6 | 7 | section '.text' executable align 16 8 | 9 | main: 10 | mov ecx,[esp+4] 11 | mov [argc],ecx 12 | mov ebx,[esp+8] 13 | mov [argv],ebx 14 | 15 | mov [display_handle],1 16 | 17 | call get_params 18 | jnc make_listing 19 | 20 | mov esi,_usage 21 | call display_string 22 | ccall exit,2 23 | 24 | make_listing: 25 | call listing 26 | ccall exit,0 27 | 28 | error: 29 | mov [display_handle],2 30 | mov esi,_error_prefix 31 | call display_string 32 | pop esi 33 | call display_string 34 | mov esi,_error_suffix 35 | call display_string 36 | ccall exit,0 37 | 38 | get_params: 39 | mov ecx,[argc] 40 | mov ebx,[argv] 41 | add ebx,4 42 | dec ecx 43 | jz bad_params 44 | get_param: 45 | mov esi,[ebx] 46 | mov al,[esi] 47 | cmp al,'-' 48 | je option_param 49 | cmp [input_file],0 50 | jne get_output_file 51 | mov [input_file],esi 52 | jmp next_param 53 | get_output_file: 54 | cmp [output_file],0 55 | jne bad_params 56 | mov [output_file],esi 57 | jmp next_param 58 | option_param: 59 | inc esi 60 | lodsb 61 | cmp al,'a' 62 | je addresses_option 63 | cmp al,'A' 64 | je addresses_option 65 | cmp al,'b' 66 | je bytes_per_line_option 67 | cmp al,'B' 68 | je bytes_per_line_option 69 | bad_params: 70 | stc 71 | ret 72 | addresses_option: 73 | cmp byte [esi],0 74 | jne bad_params 75 | mov [show_addresses],1 76 | jmp next_param 77 | bytes_per_line_option: 78 | cmp byte [esi],0 79 | jne get_bytes_per_line_setting 80 | dec ecx 81 | jz bad_params 82 | add ebx,4 83 | mov esi,[ebx] 84 | get_bytes_per_line_setting: 85 | call get_option_value 86 | or edx,edx 87 | jz bad_params 88 | cmp edx,1000 89 | ja bad_params 90 | mov [code_bytes_per_line],edx 91 | next_param: 92 | add ebx,4 93 | dec ecx 94 | jnz get_param 95 | cmp [input_file],0 96 | je bad_params 97 | cmp [output_file],0 98 | je bad_params 99 | clc 100 | ret 101 | get_option_value: 102 | xor eax,eax 103 | mov edx,eax 104 | get_option_digit: 105 | lodsb 106 | cmp al,20h 107 | je option_value_ok 108 | cmp al,0Dh 109 | je option_value_ok 110 | or al,al 111 | jz option_value_ok 112 | sub al,30h 113 | jc invalid_option_value 114 | cmp al,9 115 | ja invalid_option_value 116 | imul edx,10 117 | jo invalid_option_value 118 | add edx,eax 119 | jc invalid_option_value 120 | jmp get_option_digit 121 | option_value_ok: 122 | dec esi 123 | clc 124 | ret 125 | invalid_option_value: 126 | stc 127 | ret 128 | 129 | include 'system.inc' 130 | 131 | include '..\listing.inc' 132 | 133 | section '.data' writeable align 4 134 | 135 | input_file dd 0 136 | output_file dd 0 137 | code_bytes_per_line dd 16 138 | show_addresses db 0 139 | 140 | line_break db 0Dh,0Ah 141 | 142 | _usage db 'listing generator for flat assembler',0Dh,0Ah 143 | db 'usage: listing ',0Dh,0Ah 144 | db 'optional settings:',0Dh,0Ah 145 | db ' -a show target addresses for assembled code',0Dh,0Ah 146 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 147 | db 0 148 | _error_prefix db 'error: ',0 149 | _error_suffix db '.',0Dh,0Ah,0 150 | 151 | section '.bss' writeable align 4 152 | 153 | argc dd ? 154 | argv dd ? 155 | 156 | input dd ? 157 | assembled_code dd ? 158 | assembled_code_length dd ? 159 | code_end dd ? 160 | code_offset dd ? 161 | code_length dd ? 162 | output_handle dd ? 163 | output_buffer dd ? 164 | current_source_file dd ? 165 | current_source_line dd ? 166 | source dd ? 167 | source_length dd ? 168 | maximum_address_length dd ? 169 | address_start dd ? 170 | last_listed_address dd ? 171 | 172 | display_handle dd ? 173 | character db ? 174 | 175 | params rb 1000h 176 | characters rb 100h 177 | buffer rb 1000h 178 | -------------------------------------------------------------------------------- /INCLUDE/API/COMCTL32.INC: -------------------------------------------------------------------------------- 1 | 2 | ; COMCTL32 API calls 3 | 4 | import comctl32,\ 5 | CreateMappedBitmap,'CreateMappedBitmap',\ 6 | CreatePropertySheetPageA,'CreatePropertySheetPageA',\ 7 | CreatePropertySheetPageW,'CreatePropertySheetPageW',\ 8 | CreateStatusWindowA,'CreateStatusWindowA',\ 9 | CreateStatusWindowW,'CreateStatusWindowW',\ 10 | CreateToolbar,'CreateToolbar',\ 11 | CreateToolbarEx,'CreateToolbarEx',\ 12 | CreateUpDownControl,'CreateUpDownControl',\ 13 | DestroyPropertySheetPage,'DestroyPropertySheetPage',\ 14 | DrawInsert,'DrawInsert',\ 15 | DrawStatusTextA,'DrawStatusTextA',\ 16 | DrawStatusTextW,'DrawStatusTextW',\ 17 | FlatSB_EnableScrollBar,'FlatSB_EnableScrollBar',\ 18 | FlatSB_GetScrollInfo,'FlatSB_GetScrollInfo',\ 19 | FlatSB_GetScrollPos,'FlatSB_GetScrollPos',\ 20 | FlatSB_GetScrollProp,'FlatSB_GetScrollProp',\ 21 | FlatSB_GetScrollRange,'FlatSB_GetScrollRange',\ 22 | FlatSB_SetScrollInfo,'FlatSB_SetScrollInfo',\ 23 | FlatSB_SetScrollPos,'FlatSB_SetScrollPos',\ 24 | FlatSB_SetScrollProp,'FlatSB_SetScrollProp',\ 25 | FlatSB_SetScrollRange,'FlatSB_SetScrollRange',\ 26 | FlatSB_ShowScrollBar,'FlatSB_ShowScrollBar',\ 27 | GetEffectiveClientRect,'GetEffectiveClientRect',\ 28 | ImageList_Add,'ImageList_Add',\ 29 | ImageList_AddIcon,'ImageList_AddIcon',\ 30 | ImageList_AddMasked,'ImageList_AddMasked',\ 31 | ImageList_BeginDrag,'ImageList_BeginDrag',\ 32 | ImageList_Copy,'ImageList_Copy',\ 33 | ImageList_Create,'ImageList_Create',\ 34 | ImageList_Destroy,'ImageList_Destroy',\ 35 | ImageList_DragEnter,'ImageList_DragEnter',\ 36 | ImageList_DragLeave,'ImageList_DragLeave',\ 37 | ImageList_DragMove,'ImageList_DragMove',\ 38 | ImageList_DragShowNolock,'ImageList_DragShowNolock',\ 39 | ImageList_Draw,'ImageList_Draw',\ 40 | ImageList_DrawEx,'ImageList_DrawEx',\ 41 | ImageList_DrawIndirect,'ImageList_DrawIndirect',\ 42 | ImageList_Duplicate,'ImageList_Duplicate',\ 43 | ImageList_EndDrag,'ImageList_EndDrag',\ 44 | ImageList_GetBkColor,'ImageList_GetBkColor',\ 45 | ImageList_GetDragImage,'ImageList_GetDragImage',\ 46 | ImageList_GetIcon,'ImageList_GetIcon',\ 47 | ImageList_GetIconSize,'ImageList_GetIconSize',\ 48 | ImageList_GetImageCount,'ImageList_GetImageCount',\ 49 | ImageList_GetImageInfo,'ImageList_GetImageInfo',\ 50 | ImageList_GetImageRect,'ImageList_GetImageRect',\ 51 | ImageList_LoadImageA,'ImageList_LoadImageA',\ 52 | ImageList_LoadImageW,'ImageList_LoadImageW',\ 53 | ImageList_Merge,'ImageList_Merge',\ 54 | ImageList_Read,'ImageList_Read',\ 55 | ImageList_Remove,'ImageList_Remove',\ 56 | ImageList_Replace,'ImageList_Replace',\ 57 | ImageList_ReplaceIcon,'ImageList_ReplaceIcon',\ 58 | ImageList_SetBkColor,'ImageList_SetBkColor',\ 59 | ImageList_SetDragCursorImage,'ImageList_SetDragCursorImage',\ 60 | ImageList_SetFilter,'ImageList_SetFilter',\ 61 | ImageList_SetIconSize,'ImageList_SetIconSize',\ 62 | ImageList_SetImageCount,'ImageList_SetImageCount',\ 63 | ImageList_SetOverlayImage,'ImageList_SetOverlayImage',\ 64 | ImageList_Write,'ImageList_Write',\ 65 | InitCommonControls,'InitCommonControls',\ 66 | InitCommonControlsEx,'InitCommonControlsEx',\ 67 | InitializeFlatSB,'InitializeFlatSB',\ 68 | LBItemFromPt,'LBItemFromPt',\ 69 | MakeDragList,'MakeDragList',\ 70 | MenuHelp,'MenuHelp',\ 71 | PropertySheetA,'PropertySheetA',\ 72 | PropertySheetW,'PropertySheetW',\ 73 | ShowHideMenuCtl,'ShowHideMenuCtl',\ 74 | UninitializeFlatSB,'UninitializeFlatSB',\ 75 | _TrackMouseEvent,'_TrackMouseEvent' 76 | 77 | api CreatePropertySheetPage,\ 78 | CreateStatusWindow,\ 79 | DrawStatusText,\ 80 | ImageList_LoadImage,\ 81 | PropertySheet 82 | -------------------------------------------------------------------------------- /EXAMPLES/USECOM/USECOM.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; Component Object Model usage demonstration 3 | 4 | format PE GUI 4.0 5 | entry start 6 | 7 | include 'win32a.inc' 8 | 9 | struc GUID def 10 | { 11 | match d1-d2-d3-d4-d5, def 12 | \{ 13 | .Data1 dd 0x\#d1 14 | .Data2 dw 0x\#d2 15 | .Data3 dw 0x\#d3 16 | .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh 17 | .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh 18 | \} 19 | } 20 | 21 | interface ITaskBarList,\ 22 | QueryInterface,\ 23 | AddRef,\ 24 | Release,\ 25 | HrInit,\ 26 | AddTab,\ 27 | DeleteTab,\ 28 | ActivateTab,\ 29 | SetActiveAlt 30 | 31 | CLSCTX_INPROC_SERVER = 0x1 32 | CLSCTX_INPROC_HANDLER = 0x2 33 | CLSCTX_LOCAL_SERVER = 0x4 34 | CLSCTX_INPROC_SERVER16 = 0x8 35 | CLSCTX_REMOTE_SERVER = 0x10 36 | CLSCTX_INPROC_HANDLER16 = 0x20 37 | CLSCTX_INPROC_SERVERX86 = 0x40 38 | CLSCTX_INPROC_HANDLERX86 = 0x80 39 | CLSCTX_ESERVER_HANDLER = 0x100 40 | CLSCTX_NO_CODE_DOWNLOAD = 0x400 41 | CLSCTX_NO_CUSTOM_MARSHAL = 0x1000 42 | CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000 43 | CLSCTX_NO_FAILURE_LOG = 0x4000 44 | CLSCTX_DISABLE_AAA = 0x8000 45 | CLSCTX_ENABLE_AAA = 0x10000 46 | CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000 47 | 48 | ID_EXIT = IDCANCEL 49 | ID_SHOW = 100 50 | ID_HIDE = 101 51 | 52 | IDD_COMDEMO = 1 53 | 54 | section '.text' code readable executable 55 | 56 | start: 57 | 58 | invoke CoInitialize,NULL 59 | invoke CoCreateInstance,CLSID_TaskbarList,NULL,CLSCTX_INPROC_SERVER,IID_ITaskbarList,ShellTaskBar 60 | 61 | invoke GetModuleHandle,0 62 | invoke DialogBoxParam,eax,IDD_COMDEMO,HWND_DESKTOP,COMDemo,0 63 | 64 | cominvk ShellTaskBar,Release 65 | 66 | invoke ExitProcess,0 67 | 68 | proc COMDemo hwnd,msg,wparam,lparam 69 | push ebx esi edi 70 | cmp [msg],WM_INITDIALOG 71 | je .wminitdialog 72 | cmp [msg],WM_COMMAND 73 | je .wmcommand 74 | cmp [msg],WM_CLOSE 75 | je .wmclose 76 | xor eax,eax 77 | jmp .finish 78 | .wminitdialog: 79 | jmp .processed 80 | .wmcommand: 81 | cmp [wparam],BN_CLICKED shl 16 + ID_EXIT 82 | je .wmclose 83 | cmp [wparam],BN_CLICKED shl 16 + ID_SHOW 84 | je .show 85 | cmp [wparam],BN_CLICKED shl 16 + ID_HIDE 86 | jne .processed 87 | .hide: 88 | cominvk ShellTaskBar,HrInit 89 | cominvk ShellTaskBar,DeleteTab,[hwnd] 90 | jmp .processed 91 | .show: 92 | mov ebx,[ShellTaskBar] 93 | comcall ebx,ITaskBarList,HrInit 94 | comcall ebx,ITaskBarList,AddTab,[hwnd] 95 | comcall ebx,ITaskBarList,ActivateTab,[hwnd] 96 | jmp .processed 97 | .wmclose: 98 | invoke EndDialog,[hwnd],0 99 | .processed: 100 | mov eax,1 101 | .finish: 102 | pop edi esi ebx 103 | ret 104 | endp 105 | 106 | section '.data' data readable writeable 107 | 108 | CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090 109 | IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090 110 | 111 | ShellTaskBar ITaskBarList 112 | 113 | section '.idata' import data readable 114 | 115 | library kernel,'KERNEL32.DLL',\ 116 | user,'USER32.DLL',\ 117 | ole,'OLE32.DLL' 118 | 119 | import kernel,\ 120 | GetModuleHandle,'GetModuleHandleA',\ 121 | ExitProcess,'ExitProcess' 122 | 123 | import user,\ 124 | DialogBoxParam,'DialogBoxParamA',\ 125 | EndDialog,'EndDialog' 126 | 127 | import ole,\ 128 | CoInitialize,'CoInitialize',\ 129 | CoCreateInstance,'CoCreateInstance' 130 | 131 | section '.rsrc' resource data readable 132 | 133 | directory RT_DIALOG,dialogs 134 | 135 | resource dialogs,\ 136 | IDD_COMDEMO,LANG_ENGLISH+SUBLANG_DEFAULT,comdemo 137 | 138 | dialog comdemo,'Taskbar item control',70,70,170,24,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME 139 | dialogitem 'BUTTON','Show',ID_SHOW,4,4,45,15,WS_VISIBLE+WS_TABSTOP 140 | dialogitem 'BUTTON','Hide',ID_HIDE,54,4,45,15,WS_VISIBLE+WS_TABSTOP 141 | dialogitem 'BUTTON','Exit',ID_EXIT,120,4,45,15,WS_VISIBLE+WS_TABSTOP 142 | enddialog 143 | -------------------------------------------------------------------------------- /EXAMPLES/DIALOG/DIALOG.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; DialogBox example 3 | 4 | format PE GUI 4.0 5 | entry start 6 | 7 | include 'win32a.inc' 8 | 9 | ID_CAPTION = 101 10 | ID_MESSAGE = 102 11 | ID_ICONERROR = 201 12 | ID_ICONINFORMATION = 202 13 | ID_ICONQUESTION = 203 14 | ID_ICONWARNING = 204 15 | ID_TOPMOST = 301 16 | 17 | section '.text' code readable executable 18 | 19 | start: 20 | 21 | invoke GetModuleHandle,0 22 | invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0 23 | or eax,eax 24 | jz exit 25 | invoke MessageBox,HWND_DESKTOP,message,caption,[flags] 26 | exit: 27 | invoke ExitProcess,0 28 | 29 | proc DialogProc hwnddlg,msg,wparam,lparam 30 | push ebx esi edi 31 | cmp [msg],WM_INITDIALOG 32 | je .wminitdialog 33 | cmp [msg],WM_COMMAND 34 | je .wmcommand 35 | cmp [msg],WM_CLOSE 36 | je .wmclose 37 | xor eax,eax 38 | jmp .finish 39 | .wminitdialog: 40 | invoke CheckRadioButton,[hwnddlg],ID_ICONERROR,ID_ICONWARNING,ID_ICONINFORMATION 41 | jmp .processed 42 | .wmcommand: 43 | cmp [wparam],BN_CLICKED shl 16 + IDCANCEL 44 | je .wmclose 45 | cmp [wparam],BN_CLICKED shl 16 + IDOK 46 | jne .processed 47 | invoke GetDlgItemText,[hwnddlg],ID_CAPTION,caption,40h 48 | invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,100h 49 | mov [flags],MB_OK 50 | invoke IsDlgButtonChecked,[hwnddlg],ID_ICONERROR 51 | cmp eax,BST_CHECKED 52 | jne .iconerror_ok 53 | or [flags],MB_ICONERROR 54 | .iconerror_ok: 55 | invoke IsDlgButtonChecked,[hwnddlg],ID_ICONINFORMATION 56 | cmp eax,BST_CHECKED 57 | jne .iconinformation_ok 58 | or [flags],MB_ICONINFORMATION 59 | .iconinformation_ok: 60 | invoke IsDlgButtonChecked,[hwnddlg],ID_ICONQUESTION 61 | cmp eax,BST_CHECKED 62 | jne .iconquestion_ok 63 | or [flags],MB_ICONQUESTION 64 | .iconquestion_ok: 65 | invoke IsDlgButtonChecked,[hwnddlg],ID_ICONWARNING 66 | cmp eax,BST_CHECKED 67 | jne .iconwarning_ok 68 | or [flags],MB_ICONWARNING 69 | .iconwarning_ok: 70 | invoke IsDlgButtonChecked,[hwnddlg],ID_TOPMOST 71 | cmp eax,BST_CHECKED 72 | jne .topmost_ok 73 | or [flags],MB_TOPMOST 74 | .topmost_ok: 75 | invoke EndDialog,[hwnddlg],1 76 | jmp .processed 77 | .wmclose: 78 | invoke EndDialog,[hwnddlg],0 79 | .processed: 80 | mov eax,1 81 | .finish: 82 | pop edi esi ebx 83 | ret 84 | endp 85 | 86 | section '.bss' readable writeable 87 | 88 | flags dd ? 89 | caption rb 40h 90 | message rb 100h 91 | 92 | section '.idata' import data readable writeable 93 | 94 | library kernel,'KERNEL32.DLL',\ 95 | user,'USER32.DLL' 96 | 97 | import kernel,\ 98 | GetModuleHandle,'GetModuleHandleA',\ 99 | ExitProcess,'ExitProcess' 100 | 101 | import user,\ 102 | DialogBoxParam,'DialogBoxParamA',\ 103 | CheckRadioButton,'CheckRadioButton',\ 104 | GetDlgItemText,'GetDlgItemTextA',\ 105 | IsDlgButtonChecked,'IsDlgButtonChecked',\ 106 | MessageBox,'MessageBoxA',\ 107 | EndDialog,'EndDialog' 108 | 109 | section '.rsrc' resource data readable 110 | 111 | directory RT_DIALOG,dialogs 112 | 113 | resource dialogs,\ 114 | 37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration 115 | 116 | dialog demonstration,'Create message box',70,70,190,175,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME 117 | dialogitem 'STATIC','&Caption:',-1,10,10,70,8,WS_VISIBLE 118 | dialogitem 'EDIT','',ID_CAPTION,10,20,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP 119 | dialogitem 'STATIC','&Message:',-1,10,40,70,8,WS_VISIBLE 120 | dialogitem 'EDIT','',ID_MESSAGE,10,50,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL 121 | dialogitem 'BUTTON','&Icon',-1,10,70,80,70,WS_VISIBLE+BS_GROUPBOX 122 | dialogitem 'BUTTON','&Error',ID_ICONERROR,20,82,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON+WS_TABSTOP+WS_GROUP 123 | dialogitem 'BUTTON','I&nformation',ID_ICONINFORMATION,20,95,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON 124 | dialogitem 'BUTTON','&Question',ID_ICONQUESTION,20,108,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON 125 | dialogitem 'BUTTON','&Warning',ID_ICONWARNING,20,121,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON 126 | dialogitem 'BUTTON','&Style',-1,100,70,80,70,WS_VISIBLE+BS_GROUPBOX 127 | dialogitem 'BUTTON','&Top most',ID_TOPMOST,110,82,60,13,WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX 128 | dialogitem 'BUTTON','OK',IDOK,85,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON 129 | dialogitem 'BUTTON','C&ancel',IDCANCEL,135,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON 130 | enddialog 131 | -------------------------------------------------------------------------------- /EXAMPLES/DDRAW/GIF87A.INC: -------------------------------------------------------------------------------- 1 | 2 | virtual at buffer 3 | GIFHEADER: 4 | .ID dd ? 5 | .ver dw ? 6 | .width dw ? 7 | .height dw ? 8 | .bits db ? 9 | .background db ? 10 | .reserved db ? 11 | .length = $ - GIFHEADER 12 | end virtual 13 | 14 | load_picture: 15 | 16 | invoke CreateFileA,esi,GENERIC_READ,0,0,OPEN_EXISTING,0,0 17 | mov edi,eax 18 | invoke ReadFile,edi,GIFHEADER,40000h,bytes_count,0 19 | invoke CloseHandle,edi 20 | 21 | cmp [GIFHEADER.ID],'GIF8' 22 | jne picture_error 23 | cmp [GIFHEADER.ver],'7a' 24 | jne picture_error 25 | 26 | mov al,[GIFHEADER.bits] 27 | and al,10000111b 28 | cmp al,10000111b 29 | jne picture_error 30 | 31 | add [bytes_count],buffer 32 | 33 | mov esi,buffer+GIFHEADER.length+256*3 34 | mov edi,esi 35 | 36 | xor eax,eax 37 | find_image: 38 | cmp esi,[bytes_count] 39 | jae picture_error 40 | lodsb 41 | cmp al,',' 42 | je image_found 43 | cmp al,'!' 44 | jne picture_error 45 | inc esi 46 | skip_application_data: 47 | lodsb 48 | add esi,eax 49 | or al,al 50 | jnz skip_application_data 51 | jmp find_image 52 | image_found: 53 | add esi,4 54 | xor eax,eax 55 | lodsw 56 | mov ebx,eax 57 | lodsw 58 | inc esi 59 | cmp byte [esi],8 60 | jne picture_error 61 | inc esi 62 | 63 | mov [ddsd.dwSize],sizeof.DDSURFACEDESC 64 | mov [ddsd.dwFlags],DDSD_CAPS+DDSD_WIDTH+DDSD_HEIGHT+DDSD_CKSRCBLT 65 | mov [ddsd.ddsCaps.dwCaps],DDSCAPS_OFFSCREENPLAIN+DDSCAPS_SYSTEMMEMORY 66 | mov [ddsd.dwWidth],ebx 67 | mov [ddsd.dwHeight],eax 68 | movzx eax,[GIFHEADER.background] 69 | mov [ddsd.ddckCKSrcBlt.dwColorSpaceLowValue],eax 70 | mov [ddsd.ddckCKSrcBlt.dwColorSpaceHighValue],eax 71 | cominvk DDraw,CreateSurface,\ 72 | ddsd,DDSPicture,0 73 | or eax,eax 74 | jnz picture_error 75 | cominvk DDSPicture,Lock,\ 76 | 0,ddsd,DDLOCK_WAIT,0 77 | 78 | mov edi,esi 79 | mov edx,esi 80 | mov ebx,buffer 81 | add ebx,[bytes_count] 82 | link_streams: 83 | cmp esi,[bytes_count] 84 | jae picture_error 85 | lodsb 86 | movzx ecx,al 87 | rep movsb 88 | or al,al 89 | jnz link_streams 90 | 91 | mov edi,[ddsd.lpSurface] 92 | mov ebx,edx 93 | mov [LZW_bits],0 94 | LZW_clear: 95 | xor edx,edx 96 | LZW_decompress_loop: 97 | mov ch,9 98 | cmp edx,(100h-2)*8 99 | jbe LZW_read_bits 100 | mov ch,10 101 | cmp edx,(300h-2)*8 102 | jbe LZW_read_bits 103 | mov ch,11 104 | cmp edx,(700h-2)*8 105 | jbe LZW_read_bits 106 | mov ch,12 107 | LZW_read_bits: 108 | mov cl,[LZW_bits] 109 | mov eax,[ebx] 110 | shr eax,cl 111 | xchg cl,ch 112 | mov esi,1 113 | shl esi,cl 114 | dec esi 115 | and eax,esi 116 | add cl,ch 117 | LZW_read_bits_count: 118 | cmp cl,8 119 | jbe LZW_read_bits_ok 120 | sub cl,8 121 | inc ebx 122 | jmp LZW_read_bits_count 123 | LZW_read_bits_ok: 124 | mov [LZW_bits],cl 125 | cmp eax,100h 126 | jb LZW_single_byte 127 | je LZW_clear 128 | sub eax,102h 129 | jc LZW_end 130 | shl eax,3 131 | cmp eax,edx 132 | ja picture_error 133 | mov ecx,[LZW_table+eax] 134 | mov esi,[LZW_table+eax+4] 135 | mov [LZW_table+edx+4],edi 136 | rep movsb 137 | mov eax,[LZW_table+eax] 138 | inc eax 139 | mov [LZW_table+edx],eax 140 | jmp LZW_decompress_next 141 | LZW_single_byte: 142 | mov [LZW_table+edx],2 143 | mov [LZW_table+edx+4],edi 144 | stosb 145 | LZW_decompress_next: 146 | add edx,8 147 | jmp LZW_decompress_loop 148 | LZW_end: 149 | 150 | cominvk DDSPicture,Unlock,0 151 | 152 | mov eax,[DDSPicture] 153 | clc 154 | ret 155 | 156 | picture_error: 157 | stc 158 | ret 159 | 160 | load_palette: 161 | 162 | invoke CreateFileA,esi,GENERIC_READ,0,0,OPEN_EXISTING,0,0 163 | mov edi,eax 164 | invoke ReadFile,edi,buffer,GIFHEADER.length+256*3,bytes_count,0 165 | cmp [bytes_count],GIFHEADER.length+256*3 166 | jne picture_error 167 | invoke CloseHandle,edi 168 | 169 | cmp [GIFHEADER.ID],'GIF8' 170 | jne picture_error 171 | cmp [GIFHEADER.ver],'7a' 172 | jne picture_error 173 | mov al,[GIFHEADER.bits] 174 | and al,111b 175 | cmp al,111b 176 | jne picture_error 177 | 178 | mov esi,buffer+GIFHEADER.length 179 | mov edi,buffer+400h 180 | mov ecx,256 181 | convert_palette: 182 | movsw 183 | movsb 184 | xor al,al 185 | stosb 186 | loop convert_palette 187 | 188 | cominvk DDraw,CreatePalette,\ 189 | DDPCAPS_8BIT+DDPCAPS_ALLOW256,buffer+400h,DDPalette,0 190 | or eax,eax 191 | jnz picture_error 192 | 193 | clc 194 | ret 195 | -------------------------------------------------------------------------------- /TOOLS/DOS/SYSTEM.INC: -------------------------------------------------------------------------------- 1 | 2 | display_string: 3 | lods byte [esi] 4 | or al,al 5 | jz string_end 6 | mov dl,al 7 | mov ah,2 8 | int 21h 9 | jmp display_string 10 | string_end: 11 | ret 12 | alloc: 13 | push ebx esi edi 14 | mov cx,ax 15 | shr eax,16 16 | mov bx,ax 17 | mov ax,501h 18 | int 31h 19 | jc dpmi_allocation_failed 20 | mov ax,bx 21 | shl eax,16 22 | mov ax,cx 23 | mov edx,main 24 | shl edx,4 25 | sub eax,edx 26 | mov bx,si 27 | shl ebx,16 28 | mov bx,di 29 | mov ecx,[memory_handles_count] 30 | inc [memory_handles_count] 31 | shl ecx,3 32 | add ecx,memory_handles 33 | mov [ecx],eax 34 | mov [ecx+4],ebx 35 | pop edi esi ebx 36 | clc 37 | ret 38 | dpmi_allocation_failed: 39 | pop edi esi ebx 40 | stc 41 | ret 42 | free: 43 | push ebx esi edi 44 | mov esi,memory_handles 45 | mov ecx,[memory_handles_count] 46 | find_memory_handle: 47 | cmp eax,[esi] 48 | je memory_handle_found 49 | add esi,8 50 | loop find_memory_handle 51 | pop edi esi 52 | ret 53 | memory_handle_found: 54 | mov ebx,[esi+4] 55 | dec [memory_handles_count] 56 | dec ecx 57 | jz free_memory 58 | remove_memory_handle: 59 | mov edx,[esi+8] 60 | mov edi,[esi+8+4] 61 | mov [esi],edx 62 | mov [esi+4],edi 63 | add esi,8 64 | loop remove_memory_handle 65 | free_memory: 66 | mov esi,ebx 67 | shr esi,16 68 | mov di,bx 69 | mov ax,502h 70 | int 31h 71 | pop edi esi ebx 72 | ret 73 | open: 74 | push esi edi ebp 75 | call adapt_path 76 | mov ax,716Ch 77 | mov bx,100000b 78 | mov dx,1 79 | xor cx,cx 80 | xor si,si 81 | call dos_int 82 | jnc open_done 83 | cmp ax,7100h 84 | je old_open 85 | stc 86 | jmp open_done 87 | old_open: 88 | mov ax,3D00h 89 | xor dx,dx 90 | call dos_int 91 | open_done: 92 | mov bx,ax 93 | pop ebp edi esi 94 | ret 95 | adapt_path: 96 | mov esi,edx 97 | mov edi,buffer 98 | copy_path: 99 | lodsb 100 | cmp al,'/' 101 | jne path_char_ok 102 | mov al,'\' 103 | path_char_ok: 104 | stosb 105 | or al,al 106 | jnz copy_path 107 | ret 108 | dos_int: 109 | push 0 0 0 110 | pushw buffer_segment buffer_segment 111 | stc 112 | pushfw 113 | push eax 114 | push ecx 115 | push edx 116 | push ebx 117 | push 0 118 | push ebp 119 | push esi 120 | push edi 121 | mov ax,300h 122 | mov bx,21h 123 | xor cx,cx 124 | mov edi,esp 125 | push es ss 126 | pop es 127 | int 31h 128 | pop es 129 | mov edi,[esp] 130 | mov esi,[esp+4] 131 | mov ebp,[esp+8] 132 | mov ebx,[esp+10h] 133 | mov edx,[esp+14h] 134 | mov ecx,[esp+18h] 135 | mov ah,[esp+20h] 136 | add esp,32h 137 | sahf 138 | mov eax,[esp-32h+1Ch] 139 | ret 140 | create: 141 | push esi edi ebp 142 | call adapt_path 143 | mov ax,716Ch 144 | mov bx,100001b 145 | mov dx,10010b 146 | xor cx,cx 147 | xor si,si 148 | xor di,di 149 | call dos_int 150 | jnc create_done 151 | cmp ax,7100h 152 | je old_create 153 | stc 154 | jmp create_done 155 | old_create: 156 | mov ah,3Ch 157 | xor cx,cx 158 | xor dx,dx 159 | call dos_int 160 | create_done: 161 | mov bx,ax 162 | pop ebp edi esi 163 | ret 164 | write: 165 | push edx esi edi ebp 166 | mov ebp,ecx 167 | mov esi,edx 168 | write_loop: 169 | mov ecx,1000h 170 | sub ebp,1000h 171 | jnc do_write 172 | add ebp,1000h 173 | mov ecx,ebp 174 | xor ebp,ebp 175 | do_write: 176 | push ecx 177 | mov edi,buffer 178 | shr ecx,2 179 | rep movsd 180 | mov ecx,[esp] 181 | and ecx,11b 182 | rep movsb 183 | pop ecx 184 | mov ah,40h 185 | xor dx,dx 186 | call dos_int 187 | or ebp,ebp 188 | jnz write_loop 189 | pop ebp edi esi edx 190 | ret 191 | read: 192 | push edx esi edi ebp 193 | mov ebp,ecx 194 | mov edi,edx 195 | read_loop: 196 | mov ecx,1000h 197 | sub ebp,1000h 198 | jnc do_read 199 | add ebp,1000h 200 | mov ecx,ebp 201 | xor ebp,ebp 202 | do_read: 203 | push ecx 204 | mov ah,3Fh 205 | xor dx,dx 206 | call dos_int 207 | cmp ax,cx 208 | jne eof 209 | mov esi,buffer 210 | mov ecx,[esp] 211 | shr ecx,2 212 | rep movsd 213 | pop ecx 214 | and ecx,11b 215 | rep movsb 216 | or ebp,ebp 217 | jnz read_loop 218 | read_done: 219 | pop ebp edi esi edx 220 | ret 221 | eof: 222 | pop ecx 223 | stc 224 | jmp read_done 225 | close: 226 | mov ah,3Eh 227 | int 21h 228 | ret 229 | lseek: 230 | mov ah,42h 231 | mov ecx,edx 232 | shr ecx,16 233 | int 21h 234 | pushf 235 | shl edx,16 236 | popf 237 | mov dx,ax 238 | mov eax,edx 239 | ret 240 | -------------------------------------------------------------------------------- /EXAMPLES/WIN64/USECOM/USECOM.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; Component Object Model usage demonstration 3 | 4 | format PE64 GUI 5.0 5 | entry start 6 | 7 | include 'win64a.inc' 8 | 9 | struc GUID def 10 | { 11 | match d1-d2-d3-d4-d5, def 12 | \{ 13 | .Data1 dd 0x\#d1 14 | .Data2 dw 0x\#d2 15 | .Data3 dw 0x\#d3 16 | .Data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh 17 | .Data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh 18 | \} 19 | } 20 | 21 | interface ITaskBarList,\ 22 | QueryInterface,\ 23 | AddRef,\ 24 | Release,\ 25 | HrInit,\ 26 | AddTab,\ 27 | DeleteTab,\ 28 | ActivateTab,\ 29 | SetActiveAlt 30 | 31 | CLSCTX_INPROC_SERVER = 0x1 32 | CLSCTX_INPROC_HANDLER = 0x2 33 | CLSCTX_LOCAL_SERVER = 0x4 34 | CLSCTX_INPROC_SERVER16 = 0x8 35 | CLSCTX_REMOTE_SERVER = 0x10 36 | CLSCTX_INPROC_HANDLER16 = 0x20 37 | CLSCTX_INPROC_SERVERX86 = 0x40 38 | CLSCTX_INPROC_HANDLERX86 = 0x80 39 | CLSCTX_ESERVER_HANDLER = 0x100 40 | CLSCTX_NO_CODE_DOWNLOAD = 0x400 41 | CLSCTX_NO_CUSTOM_MARSHAL = 0x1000 42 | CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000 43 | CLSCTX_NO_FAILURE_LOG = 0x4000 44 | CLSCTX_DISABLE_AAA = 0x8000 45 | CLSCTX_ENABLE_AAA = 0x10000 46 | CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000 47 | 48 | ID_EXIT = IDCANCEL 49 | ID_SHOW = 100 50 | ID_HIDE = 101 51 | 52 | IDD_COMDEMO = 1 53 | 54 | section '.text' code readable executable 55 | 56 | start: 57 | sub rsp,8 ; Make stack dqword aligned 58 | 59 | invoke CoInitialize,NULL 60 | invoke CoCreateInstance,CLSID_TaskbarList,NULL,CLSCTX_INPROC_SERVER,IID_ITaskbarList,ShellTaskBar 61 | 62 | invoke GetModuleHandle,0 63 | invoke DialogBoxParam,rax,IDD_COMDEMO,HWND_DESKTOP,COMDemo,0 64 | 65 | cominvk ShellTaskBar,Release 66 | 67 | invoke ExitProcess,0 68 | 69 | proc COMDemo uses rbx, hwnd,msg,wparam,lparam 70 | mov [hwnd],rcx 71 | cmp edx,WM_INITDIALOG 72 | je .wminitdialog 73 | cmp edx,WM_COMMAND 74 | je .wmcommand 75 | cmp edx,WM_CLOSE 76 | je .wmclose 77 | xor eax,eax 78 | jmp .finish 79 | .wminitdialog: 80 | jmp .processed 81 | .wmcommand: 82 | cmp r8,BN_CLICKED shl 16 + ID_EXIT 83 | je .wmclose 84 | cmp r8,BN_CLICKED shl 16 + ID_SHOW 85 | je .show 86 | cmp r8,BN_CLICKED shl 16 + ID_HIDE 87 | jne .processed 88 | .hide: 89 | cominvk ShellTaskBar,HrInit 90 | cominvk ShellTaskBar,DeleteTab,[hwnd] 91 | jmp .processed 92 | .show: 93 | mov rbx,[ShellTaskBar] 94 | comcall rbx,ITaskBarList,HrInit 95 | comcall rbx,ITaskBarList,AddTab,[hwnd] 96 | comcall rbx,ITaskBarList,ActivateTab,[hwnd] 97 | jmp .processed 98 | .wmclose: 99 | invoke EndDialog,[hwnd],0 100 | .processed: 101 | mov eax,1 102 | .finish: 103 | ret 104 | endp 105 | 106 | section '.data' data readable writeable 107 | 108 | CLSID_TaskbarList GUID 56FDF344-FD6D-11D0-958A-006097C9A090 109 | IID_ITaskbarList GUID 56FDF342-FD6D-11D0-958A-006097C9A090 110 | 111 | ShellTaskBar ITaskBarList 112 | 113 | section '.idata' import data readable 114 | 115 | library kernel,'KERNEL32.DLL',\ 116 | user,'USER32.DLL',\ 117 | ole,'OLE32.DLL' 118 | 119 | import kernel,\ 120 | GetModuleHandle,'GetModuleHandleA',\ 121 | ExitProcess,'ExitProcess' 122 | 123 | import user,\ 124 | DialogBoxParam,'DialogBoxParamA',\ 125 | EndDialog,'EndDialog' 126 | 127 | import ole,\ 128 | CoInitialize,'CoInitialize',\ 129 | CoCreateInstance,'CoCreateInstance' 130 | 131 | section '.rsrc' resource data readable 132 | 133 | directory RT_DIALOG,dialogs 134 | 135 | resource dialogs,\ 136 | IDD_COMDEMO,LANG_ENGLISH+SUBLANG_DEFAULT,comdemo 137 | 138 | dialog comdemo,'Taskbar item control',70,70,170,24,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME 139 | dialogitem 'BUTTON','Show',ID_SHOW,4,4,45,15,WS_VISIBLE+WS_TABSTOP 140 | dialogitem 'BUTTON','Hide',ID_HIDE,54,4,45,15,WS_VISIBLE+WS_TABSTOP 141 | dialogitem 'BUTTON','Exit',ID_EXIT,120,4,45,15,WS_VISIBLE+WS_TABSTOP 142 | enddialog 143 | -------------------------------------------------------------------------------- /EXTENSIONS/ERRORS.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2015, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | invalid_parameter: 7 | mov eax,FASM_INVALID_PARAMETER 8 | jmp general_error 9 | out_of_memory: 10 | mov eax,FASM_OUT_OF_MEMORY 11 | jmp general_error 12 | stack_overflow: 13 | mov eax,FASM_STACK_OVERFLOW 14 | jmp general_error 15 | main_file_not_found: 16 | mov eax,FASM_SOURCE_NOT_FOUND 17 | jmp general_error 18 | unexpected_end_of_file: 19 | mov eax,FASM_UNEXPECTED_END_OF_SOURCE 20 | jmp general_error 21 | code_cannot_be_generated: 22 | mov eax,FASM_CANNOT_GENERATE_CODE 23 | jmp general_error 24 | format_limitations_exceeded: 25 | mov eax,FASM_FORMAT_LIMITATIONS_EXCEDDED 26 | jmp general_error 27 | invalid_definition: 28 | mov eax,FASM_INVALID_DEFINITION 29 | jmp general_error 30 | write_failed: 31 | mov eax,FASM_WRITE_FAILED 32 | jmp general_error 33 | 34 | file_not_found: 35 | mov eax,FASMERR_FILE_NOT_FOUND 36 | jmp assembler_error 37 | error_reading_file: 38 | mov eax,FASMERR_ERROR_READING_FILE 39 | jmp assembler_error 40 | invalid_file_format: 41 | mov eax,FASMERR_INVALID_FILE_FORMAT 42 | jmp assembler_error 43 | invalid_macro_arguments: 44 | mov eax,FASMERR_INVALID_MACRO_ARGUMENTS 45 | jmp assembler_error 46 | incomplete_macro: 47 | mov eax,FASMERR_INCOMPLETE_MACRO 48 | jmp assembler_error 49 | unexpected_characters: 50 | mov eax,FASMERR_UNEXPECTED_CHARACTERS 51 | jmp assembler_error 52 | invalid_argument: 53 | mov eax,FASMERR_INVALID_ARGUMENT 54 | jmp assembler_error 55 | illegal_instruction: 56 | mov eax,FASMERR_ILLEGAL_INSTRUCTION 57 | jmp assembler_error 58 | invalid_operand: 59 | mov eax,FASMERR_INVALID_OPERAND 60 | jmp assembler_error 61 | invalid_operand_size: 62 | mov eax,FASMERR_INVALID_OPERAND_SIZE 63 | jmp assembler_error 64 | operand_size_not_specified: 65 | mov eax,FASMERR_OPERAND_SIZE_NOT_SPECIFIED 66 | jmp assembler_error 67 | operand_sizes_do_not_match: 68 | mov eax,FASMERR_OPERAND_SIZES_DO_NOT_MATCH 69 | jmp assembler_error 70 | invalid_address_size: 71 | mov eax,FASMERR_INVALID_ADDRESS_SIZE 72 | jmp assembler_error 73 | address_sizes_do_not_agree: 74 | mov eax,FASMERR_ADDRESS_SIZES_DO_NOT_AGREE 75 | jmp assembler_error 76 | disallowed_combination_of_registers: 77 | mov eax,FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS 78 | jmp assembler_error 79 | long_immediate_not_encodable: 80 | mov eax,FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE 81 | jmp assembler_error 82 | relative_jump_out_of_range: 83 | mov eax,FASMERR_RELATIVE_JUMP_OUT_OF_RANGE 84 | jmp assembler_error 85 | invalid_expression: 86 | mov eax,FASMERR_INVALID_EXPRESSION 87 | jmp assembler_error 88 | invalid_address: 89 | mov eax,FASMERR_INVALID_ADDRESS 90 | jmp assembler_error 91 | invalid_value: 92 | mov eax,FASMERR_INVALID_VALUE 93 | jmp assembler_error 94 | value_out_of_range: 95 | mov eax,FASMERR_VALUE_OUT_OF_RANGE 96 | jmp assembler_error 97 | undefined_symbol: 98 | mov eax,FASMERR_UNDEFINED_SYMBOL 99 | jmp assembler_error 100 | invalid_use_of_symbol: 101 | mov eax,FASMERR_INVALID_USE_OF_SYMBOL 102 | jmp assembler_error 103 | name_too_long: 104 | mov eax,FASMERR_NAME_TOO_LONG 105 | jmp assembler_error 106 | invalid_name: 107 | mov eax,FASMERR_INVALID_NAME 108 | jmp assembler_error 109 | reserved_word_used_as_symbol: 110 | mov eax,FASMERR_RESERVED_WORD_USED_AS_SYMBOL 111 | jmp assembler_error 112 | symbol_already_defined: 113 | mov eax,FASMERR_SYMBOL_ALREADY_DEFINED 114 | jmp assembler_error 115 | symbol_out_of_scope: 116 | mov eax,FASMERR_SYMBOL_OUT_OF_SCOPE 117 | jmp assembler_error 118 | missing_end_quote: 119 | mov eax,FASMERR_MISSING_END_QUOTE 120 | jmp assembler_error 121 | missing_end_directive: 122 | mov eax,FASMERR_MISSING_END_DIRECTIVE 123 | jmp assembler_error 124 | unexpected_instruction: 125 | mov eax,FASMERR_UNEXPECTED_INSTRUCTION 126 | jmp assembler_error 127 | extra_characters_on_line: 128 | mov eax,FASMERR_EXTRA_CHARACTERS_ON_LINE 129 | jmp assembler_error 130 | section_not_aligned_enough: 131 | mov eax,FASMERR_SECTION_NOT_ALIGNED_ENOUGH 132 | jmp assembler_error 133 | setting_already_specified: 134 | mov eax,FASMERR_SETTING_ALREADY_SPECIFIED 135 | jmp assembler_error 136 | data_already_defined: 137 | mov eax,FASMERR_DATA_ALREADY_DEFINED 138 | jmp assembler_error 139 | too_many_repeats: 140 | mov eax,FASMERR_TOO_MANY_REPEATS 141 | jmp assembler_error 142 | invoked_error: 143 | mov eax,FASMERR_USER_ERROR 144 | jmp assembler_error 145 | assertion_failed: 146 | mov eax,FASMERR_ASSERTION_FAILED 147 | jmp assembler_error -------------------------------------------------------------------------------- /INCLUDE/WIN32AX.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win32 programming headers (ASCII) 3 | 4 | include 'win32a.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro pushd value 10 | \{ match ,value \\{ 11 | pushx equ \\} 12 | match =pushx =invoke proc,pushx value \\{ 13 | allow_nesting 14 | invoke proc 15 | purge pushd,invoke,stdcall,cinvoke,ccall 16 | push eax 17 | pushx equ \\} 18 | match =pushx =stdcall proc,pushx value \\{ 19 | allow_nesting 20 | stdcall proc 21 | purge pushd,invoke,stdcall,cinvoke,ccall 22 | push eax 23 | pushx equ \\} 24 | match =pushx =cinvoke proc,pushx value \\{ 25 | allow_nesting 26 | cinvoke proc 27 | purge pushd,invoke,stdcall,cinvoke,ccall 28 | push eax 29 | pushx equ \\} 30 | match =pushx =ccall proc,pushx value \\{ 31 | allow_nesting 32 | ccall proc 33 | purge pushd,invoke,stdcall,cinvoke,ccall 34 | push eax 35 | pushx equ \\} 36 | match =pushx,pushx \\{ 37 | pushd 38 | pushx equ \\} 39 | restore pushx \} 40 | macro invoke proc,[arg] 41 | \{ \reverse pushd 42 | \common call [proc] \} 43 | macro stdcall proc,[arg] 44 | \{ \reverse pushd 45 | \common call proc \} 46 | macro cinvoke proc,[arg] 47 | \{ \common \local size 48 | size = 0 49 | if ~ arg eq 50 | \reverse pushd 51 | size = size+4 52 | match =double any,arg \\{ size = size+4 \\} 53 | \common end if 54 | call [proc] 55 | if size 56 | add esp,size 57 | end if \} 58 | macro ccall proc,[arg] 59 | \{ \common \local size 60 | size = 0 61 | if ~ arg eq 62 | \reverse pushd 63 | size = size+4 64 | match =double any,arg \\{ size = size+4 \\} 65 | \common end if 66 | call proc 67 | if size 68 | add esp,size 69 | end if \} } 70 | 71 | macro pushd value 72 | { match first=,more, value \{ \local ..continue 73 | call ..continue 74 | db value,0 75 | ..continue: 76 | pushd equ \} 77 | match pushd =addr var,pushd value \{ \local ..opcode,..address 78 | if +var relativeto 0 | +var relativeto $ 79 | push var 80 | else 81 | lea edx,[var] 82 | push edx 83 | end if 84 | pushd equ \} 85 | match pushd =double [var],pushd value \{ 86 | push dword [var+4] 87 | push dword [var] 88 | pushd equ \} 89 | match pushd =double =ptr var,pushd value \{ 90 | push dword [var+4] 91 | push dword [var] 92 | pushd equ \} 93 | match pushd =double num,pushd value \{ \local ..high,..low 94 | virtual at 0 95 | dq num 96 | load ..low dword from 0 97 | load ..high dword from 4 98 | end virtual 99 | push ..high 100 | push ..low 101 | pushd equ \} 102 | match pushd,pushd \{ \local ..continue 103 | if value eqtype '' 104 | call ..continue 105 | db value,0 106 | ..continue: 107 | else 108 | push value 109 | end if 110 | pushd equ \} 111 | restore pushd } 112 | 113 | allow_nesting 114 | 115 | macro import lib,[functions] 116 | { common macro import_#lib \{ import lib,functions \} } 117 | 118 | macro api [functions] 119 | { common macro all_api \{ all_api 120 | api functions \} } 121 | macro all_api {} 122 | 123 | include 'api/kernel32.inc' 124 | include 'api/user32.inc' 125 | include 'api/gdi32.inc' 126 | include 'api/advapi32.inc' 127 | include 'api/comctl32.inc' 128 | include 'api/comdlg32.inc' 129 | include 'api/shell32.inc' 130 | include 'api/wsock32.inc' 131 | 132 | purge import,api 133 | 134 | macro .data { section '.data' data readable writeable } 135 | 136 | macro .code { section '.text' code readable executable } 137 | 138 | macro .end label 139 | { 140 | entry label 141 | 142 | section '.idata' import data readable writeable 143 | 144 | library kernel32,'KERNEL32.DLL',\ 145 | user32,'USER32.DLL',\ 146 | gdi32,'GDI32.DLL',\ 147 | advapi32,'ADVAPI32.DLL',\ 148 | comctl32,'COMCTL32.DLL',\ 149 | comdlg32,'COMDLG32.DLL',\ 150 | shell32,'SHELL32.DLL',\ 151 | wsock32,'WSOCK32.DLL' 152 | 153 | import_kernel32 154 | import_user32 155 | import_gdi32 156 | import_advapi32 157 | import_comctl32 158 | import_comdlg32 159 | import_shell32 160 | import_wsock32 161 | 162 | all_api 163 | } 164 | 165 | virtual at 0 166 | xchg eax,eax 167 | detected_16bit = $-1 168 | end virtual 169 | 170 | if detected_16bit 171 | format PE GUI 4.0 172 | end if 173 | -------------------------------------------------------------------------------- /INCLUDE/WIN32WX.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win32 programming headers (WideChar) 3 | 4 | include 'win32w.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro pushd value 10 | \{ match ,value \\{ 11 | pushx equ \\} 12 | match =pushx =invoke proc,pushx value \\{ 13 | allow_nesting 14 | invoke proc 15 | purge pushd,invoke,stdcall,cinvoke,ccall 16 | push eax 17 | pushx equ \\} 18 | match =pushx =stdcall proc,pushx value \\{ 19 | allow_nesting 20 | stdcall proc 21 | purge pushd,invoke,stdcall,cinvoke,ccall 22 | push eax 23 | pushx equ \\} 24 | match =pushx =cinvoke proc,pushx value \\{ 25 | allow_nesting 26 | cinvoke proc 27 | purge pushd,invoke,stdcall,cinvoke,ccall 28 | push eax 29 | pushx equ \\} 30 | match =pushx =ccall proc,pushx value \\{ 31 | allow_nesting 32 | ccall proc 33 | purge pushd,invoke,stdcall,cinvoke,ccall 34 | push eax 35 | pushx equ \\} 36 | match =pushx,pushx \\{ 37 | pushd 38 | pushx equ \\} 39 | restore pushx \} 40 | macro invoke proc,[arg] 41 | \{ \reverse pushd 42 | \common call [proc] \} 43 | macro stdcall proc,[arg] 44 | \{ \reverse pushd 45 | \common call proc \} 46 | macro cinvoke proc,[arg] 47 | \{ \common \local size 48 | size = 0 49 | if ~ arg eq 50 | \reverse pushd 51 | size = size+4 52 | match =double any,arg \\{ size = size+4 \\} 53 | \common end if 54 | call [proc] 55 | if size 56 | add esp,size 57 | end if \} 58 | macro ccall proc,[arg] 59 | \{ \common \local size 60 | size = 0 61 | if ~ arg eq 62 | \reverse pushd 63 | size = size+4 64 | match =double any,arg \\{ size = size+4 \\} 65 | \common end if 66 | call proc 67 | if size 68 | add esp,size 69 | end if \} } 70 | 71 | macro pushd value 72 | { match first=,more, value \{ \local ..continue 73 | times 1 - (rva $ and 1) nop 74 | call ..continue 75 | du value,0 76 | ..continue: 77 | pushd equ \} 78 | match pushd =addr var,pushd value \{ \local ..opcode,..address 79 | if +var relativeto 0 | +var relativeto $ 80 | push var 81 | else 82 | lea edx,[var] 83 | push edx 84 | end if 85 | pushd equ \} 86 | match pushd =double [var],pushd value \{ 87 | push dword [var+4] 88 | push dword [var] 89 | pushd equ \} 90 | match pushd =double =ptr var,pushd value \{ 91 | push dword [var+4] 92 | push dword [var] 93 | pushd equ \} 94 | match pushd =double num,pushd value \{ \local ..high,..low 95 | virtual at 0 96 | dq num 97 | load ..low dword from 0 98 | load ..high dword from 4 99 | end virtual 100 | push ..high 101 | push ..low 102 | pushd equ \} 103 | match pushd,pushd \{ \local ..continue 104 | if value eqtype '' 105 | times 1 - (rva $ and 1) nop 106 | call ..continue 107 | du value,0 108 | ..continue: 109 | else 110 | push value 111 | end if 112 | pushd equ \} 113 | restore pushd } 114 | 115 | allow_nesting 116 | 117 | macro import lib,[functions] 118 | { common macro import_#lib \{ import lib,functions \} } 119 | 120 | macro api [functions] 121 | { common macro all_api \{ all_api 122 | api functions \} } 123 | macro all_api {} 124 | 125 | include 'api/kernel32.inc' 126 | include 'api/user32.inc' 127 | include 'api/gdi32.inc' 128 | include 'api/advapi32.inc' 129 | include 'api/comctl32.inc' 130 | include 'api/comdlg32.inc' 131 | include 'api/shell32.inc' 132 | include 'api/wsock32.inc' 133 | 134 | purge import,api 135 | 136 | macro .data { section '.data' data readable writeable } 137 | 138 | macro .code { section '.text' code readable executable } 139 | 140 | macro .end label 141 | { 142 | entry label 143 | 144 | section '.idata' import data readable writeable 145 | 146 | library kernel32,'KERNEL32.DLL',\ 147 | user32,'USER32.DLL',\ 148 | gdi32,'GDI32.DLL',\ 149 | advapi32,'ADVAPI32.DLL',\ 150 | comctl32,'COMCTL32.DLL',\ 151 | comdlg32,'COMDLG32.DLL',\ 152 | shell32,'SHELL32.DLL',\ 153 | wsock32,'WSOCK32.DLL' 154 | 155 | import_kernel32 156 | import_user32 157 | import_gdi32 158 | import_advapi32 159 | import_comctl32 160 | import_comdlg32 161 | import_shell32 162 | import_wsock32 163 | 164 | all_api 165 | } 166 | 167 | virtual at 0 168 | xchg eax,eax 169 | detected_16bit = $-1 170 | end virtual 171 | 172 | if detected_16bit 173 | format PE GUI 4.0 174 | end if 175 | -------------------------------------------------------------------------------- /TOOLS/DOS/LISTING.ASM: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_listing 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_listing: 22 | call listing 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,'-' 46 | je option_param 47 | cmp al,0Dh 48 | je all_params 49 | or al,al 50 | jz all_params 51 | cmp [es:input_file],0 52 | jne get_output_file 53 | mov [es:input_file],edi 54 | jmp process_param 55 | get_output_file: 56 | cmp [es:output_file],0 57 | jne bad_params 58 | mov [es:output_file],edi 59 | process_param: 60 | cmp al,22h 61 | je string_param 62 | copy_param: 63 | stosb 64 | lodsb 65 | cmp al,20h 66 | je param_end 67 | cmp al,0Dh 68 | je param_end 69 | or al,al 70 | jz param_end 71 | jmp copy_param 72 | string_param: 73 | lodsb 74 | cmp al,22h 75 | je string_param_end 76 | cmp al,0Dh 77 | je param_end 78 | or al,al 79 | jz param_end 80 | stosb 81 | jmp string_param 82 | option_param: 83 | lodsb 84 | cmp al,'a' 85 | je addresses_option 86 | cmp al,'A' 87 | je addresses_option 88 | cmp al,'b' 89 | je bytes_per_line_option 90 | cmp al,'B' 91 | je bytes_per_line_option 92 | invalid_option: 93 | pop ds 94 | stc 95 | ret 96 | get_option_value: 97 | xor eax,eax 98 | mov edx,eax 99 | get_option_digit: 100 | lodsb 101 | cmp al,20h 102 | je option_value_ok 103 | cmp al,0Dh 104 | je option_value_ok 105 | or al,al 106 | jz option_value_ok 107 | sub al,30h 108 | jc bad_params_value 109 | cmp al,9 110 | ja bad_params_value 111 | imul edx,10 112 | jo bad_params_value 113 | add edx,eax 114 | jc bad_params_value 115 | jmp get_option_digit 116 | option_value_ok: 117 | dec esi 118 | clc 119 | ret 120 | bad_params_value: 121 | stc 122 | ret 123 | bytes_per_line_option: 124 | lodsb 125 | cmp al,20h 126 | je bytes_per_line_option 127 | cmp al,0Dh 128 | je invalid_option 129 | or al,al 130 | jz invalid_option 131 | dec esi 132 | call get_option_value 133 | jc bad_params 134 | or edx,edx 135 | jz invalid_option 136 | cmp edx,1000 137 | ja invalid_option 138 | mov [es:code_bytes_per_line],edx 139 | jmp find_param 140 | addresses_option: 141 | lodsb 142 | cmp al,20h 143 | je set_addresses_option 144 | cmp al,0Dh 145 | je set_addresses_option 146 | or al,al 147 | jnz bad_params 148 | set_addresses_option: 149 | dec esi 150 | mov [es:show_addresses],1 151 | jmp find_param 152 | param_end: 153 | dec esi 154 | string_param_end: 155 | xor al,al 156 | stosb 157 | jmp find_param 158 | all_params: 159 | xor al,al 160 | stosb 161 | pop ds 162 | cmp [input_file],0 163 | je bad_params 164 | cmp [output_file],0 165 | je bad_params 166 | clc 167 | ret 168 | bad_params: 169 | stc 170 | ret 171 | 172 | include 'system.inc' 173 | 174 | include '..\listing.inc' 175 | 176 | _usage db 'listing generator for flat assembler',0Dh,0Ah 177 | db 'usage: listing ',0Dh,0Ah 178 | db 'optional settings:',0Dh,0Ah 179 | db ' -a show target addresses for assembled code',0Dh,0Ah 180 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 181 | db 0 182 | _error_prefix db 'error: ',0 183 | _error_suffix db '.',0Dh,0Ah,0 184 | 185 | input_file dd 0 186 | output_file dd 0 187 | code_bytes_per_line dd 16 188 | show_addresses db 0 189 | 190 | line_break db 0Dh,0Ah 191 | 192 | input dd ? 193 | assembled_code dd ? 194 | assembled_code_length dd ? 195 | code_end dd ? 196 | code_offset dd ? 197 | code_length dd ? 198 | output_handle dd ? 199 | output_buffer dd ? 200 | current_source_file dd ? 201 | current_source_line dd ? 202 | source dd ? 203 | source_length dd ? 204 | maximum_address_length dd ? 205 | address_start dd ? 206 | last_listed_address dd ? 207 | 208 | psp_selector dw ? 209 | environment_selector dw ? 210 | 211 | memory_handles_count dd ? 212 | memory_handles rd 400h 213 | 214 | params rb 1000h 215 | characters rb 100h 216 | 217 | segment buffer_segment 218 | 219 | buffer = (buffer_segment-main) shl 4 220 | 221 | db 1000h dup ? 222 | 223 | segment stack_segment 224 | 225 | stack_bottom = (stack_segment-main) shl 4 226 | 227 | db 4000h dup ? 228 | 229 | stack_top = stack_bottom + $ 230 | -------------------------------------------------------------------------------- /EXTENSIONS/FASM.ASH: -------------------------------------------------------------------------------- 1 | 2 | ; The following structure resides at the beginning of memory block provided 3 | ; to the fasm_Assemble function. The condition field contains the same value 4 | ; as the one returned by function. 5 | ; When function returns FASM_OK condition, the output_length and 6 | ; output_data fields are filled - with pointer to generated output 7 | ; (somewhere within the provided memory block) and the count of bytes stored 8 | ; there. 9 | ; When function returns FASM_ERROR, the error_code is filled with the 10 | ; code of specific error that happened and error_line is a pointer to the 11 | ; LINE_HEADER structure, providing information about the line that caused 12 | ; the error. 13 | 14 | struct FASM_STATE 15 | condition dd ? 16 | union 17 | output_length dd ? 18 | error_code dd ? 19 | ends 20 | union 21 | output_data dd ? 22 | error_line dd ? 23 | ends 24 | ends 25 | 26 | ; The following structure has two variants - it either defines the line 27 | ; that was loaded directly from source, or the line that was generated by 28 | ; macroinstruction. First case has the highest bit of line_number set to 0, 29 | ; while the second case has this bit set. 30 | ; In the first case, the file_path field contains pointer to the path of 31 | ; source file (empty string if it's the source that was provided directly to 32 | ; fasm_Assemble function), the line_number is the number of line within 33 | ; that file (starting from 1) and the file_offset field contains the offset 34 | ; within the file where the line starts. 35 | ; In the second case the macro_calling_line field contains the pointer to 36 | ; LINE_HEADER structure for the line which called the macroinstruction, and 37 | ; the macro_line field contains the pointer to LINE_HEADER structure for the 38 | ; line within the definition of macroinstruction, which generated this one. 39 | 40 | struct LINE_HEADER 41 | file_path dd ? 42 | line_number dd ? 43 | union 44 | file_offset dd ? 45 | macro_calling_line dd ? 46 | ends 47 | macro_line dd ? 48 | ends 49 | 50 | ; General errors and conditions 51 | 52 | FASM_OK = 0 ; FASM_STATE points to output 53 | FASM_WORKING = 1 54 | FASM_ERROR = 2 ; FASM_STATE contains error code 55 | FASM_INVALID_PARAMETER = -1 56 | FASM_OUT_OF_MEMORY = -2 57 | FASM_STACK_OVERFLOW = -3 58 | FASM_SOURCE_NOT_FOUND = -4 59 | FASM_UNEXPECTED_END_OF_SOURCE = -5 60 | FASM_CANNOT_GENERATE_CODE = -6 61 | FASM_FORMAT_LIMITATIONS_EXCEDDED = -7 62 | FASM_WRITE_FAILED = -8 63 | FASM_INVALID_DEFINITION = -9 64 | 65 | ; Error codes for FASM_ERROR condition 66 | 67 | FASMERR_FILE_NOT_FOUND = -101 68 | FASMERR_ERROR_READING_FILE = -102 69 | FASMERR_INVALID_FILE_FORMAT = -103 70 | FASMERR_INVALID_MACRO_ARGUMENTS = -104 71 | FASMERR_INCOMPLETE_MACRO = -105 72 | FASMERR_UNEXPECTED_CHARACTERS = -106 73 | FASMERR_INVALID_ARGUMENT = -107 74 | FASMERR_ILLEGAL_INSTRUCTION = -108 75 | FASMERR_INVALID_OPERAND = -109 76 | FASMERR_INVALID_OPERAND_SIZE = -110 77 | FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111 78 | FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112 79 | FASMERR_INVALID_ADDRESS_SIZE = -113 80 | FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114 81 | FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115 82 | FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116 83 | FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117 84 | FASMERR_INVALID_EXPRESSION = -118 85 | FASMERR_INVALID_ADDRESS = -119 86 | FASMERR_INVALID_VALUE = -120 87 | FASMERR_VALUE_OUT_OF_RANGE = -121 88 | FASMERR_UNDEFINED_SYMBOL = -122 89 | FASMERR_INVALID_USE_OF_SYMBOL = -123 90 | FASMERR_NAME_TOO_LONG = -124 91 | FASMERR_INVALID_NAME = -125 92 | FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126 93 | FASMERR_SYMBOL_ALREADY_DEFINED = -127 94 | FASMERR_MISSING_END_QUOTE = -128 95 | FASMERR_MISSING_END_DIRECTIVE = -129 96 | FASMERR_UNEXPECTED_INSTRUCTION = -130 97 | FASMERR_EXTRA_CHARACTERS_ON_LINE = -131 98 | FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132 99 | FASMERR_SETTING_ALREADY_SPECIFIED = -133 100 | FASMERR_DATA_ALREADY_DEFINED = -134 101 | FASMERR_TOO_MANY_REPEATS = -135 102 | FASMERR_SYMBOL_OUT_OF_SCOPE = -136 103 | FASMERR_USER_ERROR = -140 104 | FASMERR_ASSERTION_FAILED = -141 105 | -------------------------------------------------------------------------------- /TOOLS/WIN32/LISTING.ASM: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'listing generator for flat assembler',0Dh,0Ah 10 | db 'usage: listing ',0Dh,0Ah 11 | db 'optional settings:',0Dh,0Ah 12 | db ' -a show target addresses for assembled code',0Dh,0Ah 13 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 14 | db 0 15 | _error_prefix db 'error: ',0 16 | _error_suffix db '.',0Dh,0Ah,0 17 | 18 | line_break db 0Dh,0Ah 19 | 20 | input_file dd 0 21 | output_file dd 0 22 | code_bytes_per_line dd 16 23 | show_addresses db 0 24 | 25 | input dd ? 26 | assembled_code dd ? 27 | assembled_code_length dd ? 28 | code_end dd ? 29 | code_offset dd ? 30 | code_length dd ? 31 | output_handle dd ? 32 | output_buffer dd ? 33 | current_source_file dd ? 34 | current_source_line dd ? 35 | source dd ? 36 | source_length dd ? 37 | maximum_address_length dd ? 38 | address_start dd ? 39 | last_listed_address dd ? 40 | 41 | display_handle dd ? 42 | bytes_count dd ? 43 | 44 | params rb 1000h 45 | characters rb 100h 46 | 47 | section '.text' code readable executable 48 | 49 | start: 50 | 51 | mov [display_handle],STD_OUTPUT_HANDLE 52 | 53 | call get_params 54 | jnc make_listing 55 | 56 | mov esi,_usage 57 | call display_string 58 | invoke ExitProcess,2 59 | 60 | make_listing: 61 | call listing 62 | invoke ExitProcess,0 63 | 64 | error: 65 | mov [display_handle],STD_ERROR_HANDLE 66 | mov esi,_error_prefix 67 | call display_string 68 | pop esi 69 | call display_string 70 | mov esi,_error_suffix 71 | call display_string 72 | invoke ExitProcess,1 73 | 74 | get_params: 75 | invoke GetCommandLine 76 | mov esi,eax 77 | mov edi,params 78 | find_command_start: 79 | lodsb 80 | cmp al,20h 81 | je find_command_start 82 | cmp al,22h 83 | je skip_quoted_name 84 | skip_name: 85 | lodsb 86 | cmp al,20h 87 | je find_param 88 | or al,al 89 | jz all_params 90 | jmp skip_name 91 | skip_quoted_name: 92 | lodsb 93 | cmp al,22h 94 | je find_param 95 | or al,al 96 | jz all_params 97 | jmp skip_quoted_name 98 | find_param: 99 | lodsb 100 | cmp al,20h 101 | je find_param 102 | cmp al,'-' 103 | je option_param 104 | cmp al,0Dh 105 | je all_params 106 | or al,al 107 | jz all_params 108 | cmp [input_file],0 109 | jne get_output_file 110 | mov [input_file],edi 111 | jmp process_param 112 | get_output_file: 113 | cmp [output_file],0 114 | jne bad_params 115 | mov [output_file],edi 116 | process_param: 117 | cmp al,22h 118 | je string_param 119 | copy_param: 120 | stosb 121 | lodsb 122 | cmp al,20h 123 | je param_end 124 | cmp al,0Dh 125 | je param_end 126 | or al,al 127 | jz param_end 128 | jmp copy_param 129 | string_param: 130 | lodsb 131 | cmp al,22h 132 | je string_param_end 133 | cmp al,0Dh 134 | je param_end 135 | or al,al 136 | jz param_end 137 | stosb 138 | jmp string_param 139 | option_param: 140 | lodsb 141 | cmp al,'a' 142 | je addresses_option 143 | cmp al,'A' 144 | je addresses_option 145 | cmp al,'b' 146 | je bytes_per_line_option 147 | cmp al,'B' 148 | je bytes_per_line_option 149 | bad_params: 150 | stc 151 | ret 152 | get_option_value: 153 | xor eax,eax 154 | mov edx,eax 155 | get_option_digit: 156 | lodsb 157 | cmp al,20h 158 | je option_value_ok 159 | cmp al,0Dh 160 | je option_value_ok 161 | or al,al 162 | jz option_value_ok 163 | sub al,30h 164 | jc invalid_option_value 165 | cmp al,9 166 | ja invalid_option_value 167 | imul edx,10 168 | jo invalid_option_value 169 | add edx,eax 170 | jc invalid_option_value 171 | jmp get_option_digit 172 | option_value_ok: 173 | dec esi 174 | clc 175 | ret 176 | invalid_option_value: 177 | stc 178 | ret 179 | bytes_per_line_option: 180 | lodsb 181 | cmp al,20h 182 | je bytes_per_line_option 183 | cmp al,0Dh 184 | je bad_params 185 | or al,al 186 | jz bad_params 187 | dec esi 188 | call get_option_value 189 | or edx,edx 190 | jz bad_params 191 | cmp edx,1000 192 | ja bad_params 193 | mov [code_bytes_per_line],edx 194 | jmp find_param 195 | addresses_option: 196 | lodsb 197 | cmp al,20h 198 | je set_addresses_option 199 | cmp al,0Dh 200 | je set_addresses_option 201 | or al,al 202 | jnz bad_params 203 | set_addresses_option: 204 | dec esi 205 | mov [show_addresses],1 206 | jmp find_param 207 | param_end: 208 | dec esi 209 | string_param_end: 210 | xor al,al 211 | stosb 212 | jmp find_param 213 | all_params: 214 | cmp [input_file],0 215 | je bad_params 216 | cmp [output_file],0 217 | je bad_params 218 | clc 219 | ret 220 | 221 | include 'system.inc' 222 | 223 | include '..\listing.inc' 224 | 225 | section '.idata' import data readable writeable 226 | 227 | library kernel32,'KERNEL32.DLL' 228 | 229 | include 'api\kernel32.inc' 230 | -------------------------------------------------------------------------------- /SOURCE/IDE/MEMORY.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat editor core 3 | ; Copyright (c) 1999-2015, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | init_editor_memory: 7 | mov ecx,BLOCK_LENGTH 8 | call get_memory 9 | or eax,eax 10 | jz memory_error 11 | mov [editor_memory],eax 12 | mov dword [eax],0 13 | mov dword [eax+4],0 14 | mov dword [eax+8],ebx 15 | lea ebx,[eax+SEGMENT_LENGTH] 16 | mov [unallocated_segments],ebx 17 | mov [memory_search_segment],ebx 18 | add eax,BLOCK_LENGTH 19 | mov [unallocated_segments_end],eax 20 | mov [memory_search_block],eax 21 | mov [released_segments],0 22 | call allocate_segment 23 | mov [first_line],eax 24 | mov [lines_count],1 25 | mov [peak_line_length],0 26 | mov [caret_line],eax 27 | mov [caret_line_number],1 28 | mov [window_line],eax 29 | mov [window_line_number],1 30 | mov edi,eax 31 | xor eax,eax 32 | mov ecx,SEGMENT_HEADER_LENGTH shr 2 33 | rep stosd 34 | mov eax,20202020h 35 | mov ecx,SEGMENT_DATA_LENGTH shr 2 36 | rep stosd 37 | call allocate_segment 38 | jc memory_shortage 39 | mov [lengths_table],eax 40 | mov edi,eax 41 | xor eax,eax 42 | mov ecx,SEGMENT_LENGTH shr 2 43 | rep stosd 44 | mov [caret_position],eax 45 | mov [window_position],eax 46 | mov [selection_line],eax 47 | mov [undo_data],eax 48 | mov [redo_data],eax 49 | mov [search_data],eax 50 | mov [editor_mode],eax 51 | mov [unmodified_state],eax 52 | clc 53 | retn 54 | memory_error: 55 | stc 56 | retn 57 | 58 | reset_editor_memory: 59 | mov esi,[editor_memory] 60 | lea eax,[esi+SEGMENT_LENGTH] 61 | mov [unallocated_segments],eax 62 | mov [memory_search_segment],eax 63 | lea eax,[esi+BLOCK_LENGTH] 64 | mov [unallocated_segments_end],eax 65 | mov [memory_search_block],eax 66 | mov [released_segments],0 67 | mov ebx,[esi] 68 | release_blocks: 69 | or ebx,ebx 70 | jz release_done 71 | push dword [ebx] 72 | mov ebx,[ebx+8] 73 | call release_memory 74 | pop ebx 75 | jmp release_blocks 76 | release_done: 77 | mov ebx,[editor_memory] 78 | xor eax,eax 79 | mov [ebx],eax 80 | mov [undo_data],eax 81 | mov [redo_data],eax 82 | mov [search_data],eax 83 | call allocate_segment 84 | jc memory_shortage 85 | mov [first_line],eax 86 | mov [window_line],eax 87 | mov [caret_line],eax 88 | mov edi,eax 89 | xor eax,eax 90 | mov ecx,SEGMENT_HEADER_LENGTH shr 2 91 | rep stosd 92 | mov eax,20202020h 93 | mov ecx,SEGMENT_DATA_LENGTH shr 2 94 | rep stosd 95 | xor eax,eax 96 | mov [selection_line],eax 97 | mov [peak_line_length],eax 98 | mov [window_position],eax 99 | inc eax 100 | mov [window_line_number],eax 101 | mov [caret_line_number],eax 102 | mov [lines_count],eax 103 | call allocate_segment 104 | jc memory_shortage 105 | mov [lengths_table],eax 106 | mov edi,eax 107 | xor eax,eax 108 | mov ecx,SEGMENT_LENGTH shr 2 109 | rep stosd 110 | retn 111 | 112 | release_editor_memory: 113 | mov esi,[editor_memory] 114 | release: 115 | push dword [esi] 116 | mov ebx,[esi+8] 117 | call release_memory 118 | pop esi 119 | or esi,esi 120 | jnz release 121 | mov [editor_memory],0 122 | retn 123 | 124 | allocate_segment: 125 | mov eax,[unallocated_segments] 126 | cmp eax,[unallocated_segments_end] 127 | je simple_allocation_failed 128 | add [unallocated_segments],SEGMENT_LENGTH 129 | clc 130 | retn 131 | simple_allocation_failed: 132 | push ebx esi 133 | mov ebx,[memory_search_block] 134 | mov esi,[memory_search_segment] 135 | cmp [released_segments],16 136 | jb add_new_block 137 | find_free_segment: 138 | cmp esi,ebx 139 | je find_in_next_block 140 | cmp dword [esi],-1 141 | je reuse_segment 142 | add esi,SEGMENT_LENGTH 143 | cmp esi,[memory_search_segment] 144 | jne find_free_segment 145 | add_new_block: 146 | sub ebx,BLOCK_LENGTH 147 | find_last_memory_block: 148 | cmp dword [ebx],0 149 | je allocate_more_memory 150 | mov ebx,[ebx] 151 | jmp find_last_memory_block 152 | allocate_more_memory: 153 | mov ecx,BLOCK_LENGTH 154 | push ebx 155 | call get_memory 156 | pop esi 157 | or eax,eax 158 | jz allocation_failed 159 | mov [esi],eax 160 | mov dword [eax],0 161 | mov [eax+4],esi 162 | mov [eax+8],ebx 163 | lea ebx,[eax+BLOCK_LENGTH] 164 | mov [unallocated_segments_end],ebx 165 | add eax,SEGMENT_LENGTH 166 | lea ebx,[eax+SEGMENT_LENGTH] 167 | mov [unallocated_segments],ebx 168 | mov [released_segments],0 169 | pop esi ebx 170 | clc 171 | retn 172 | allocation_failed: 173 | xor eax,eax 174 | pop esi ebx 175 | stc 176 | retn 177 | reuse_segment: 178 | mov eax,esi 179 | mov [memory_search_block],ebx 180 | add esi,SEGMENT_LENGTH 181 | mov [memory_search_segment],esi 182 | dec [released_segments] 183 | pop esi ebx 184 | clc 185 | retn 186 | find_in_next_block: 187 | sub ebx,BLOCK_LENGTH 188 | mov esi,[ebx] 189 | lea ebx,[esi+BLOCK_LENGTH] 190 | or esi,esi 191 | jnz find_free_segment 192 | mov ebx,[editor_memory] 193 | mov esi,ebx 194 | add ebx,BLOCK_LENGTH 195 | jmp find_free_segment 196 | 197 | memory_shortage: 198 | call undo_changes 199 | jmp not_enough_memory 200 | -------------------------------------------------------------------------------- /SOURCE/ERRORS.INC: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2022, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | out_of_memory: 7 | push _out_of_memory 8 | jmp fatal_error 9 | stack_overflow: 10 | push _stack_overflow 11 | jmp fatal_error 12 | main_file_not_found: 13 | push _main_file_not_found 14 | jmp fatal_error 15 | write_failed: 16 | push _write_failed 17 | jmp fatal_error 18 | 19 | code_cannot_be_generated: 20 | push _code_cannot_be_generated 21 | jmp general_error 22 | format_limitations_exceeded: 23 | push _format_limitations_exceeded 24 | jmp general_error 25 | invalid_definition: 26 | push _invalid_definition 27 | general_error: 28 | cmp [symbols_file],0 29 | je fatal_error 30 | call dump_preprocessed_source 31 | jmp fatal_error 32 | 33 | file_not_found: 34 | push _file_not_found 35 | jmp error_with_source 36 | error_reading_file: 37 | push _error_reading_file 38 | jmp error_with_source 39 | invalid_file_format: 40 | push _invalid_file_format 41 | jmp error_with_source 42 | invalid_macro_arguments: 43 | push _invalid_macro_arguments 44 | jmp error_with_source 45 | incomplete_macro: 46 | push _incomplete_macro 47 | jmp error_with_source 48 | unexpected_characters: 49 | push _unexpected_characters 50 | jmp error_with_source 51 | invalid_argument: 52 | push _invalid_argument 53 | jmp error_with_source 54 | illegal_instruction: 55 | push _illegal_instruction 56 | jmp error_with_source 57 | invalid_operand: 58 | push _invalid_operand 59 | jmp error_with_source 60 | invalid_operand_size: 61 | push _invalid_operand_size 62 | jmp error_with_source 63 | operand_size_not_specified: 64 | push _operand_size_not_specified 65 | jmp error_with_source 66 | operand_sizes_do_not_match: 67 | push _operand_sizes_do_not_match 68 | jmp error_with_source 69 | invalid_address_size: 70 | push _invalid_address_size 71 | jmp error_with_source 72 | address_sizes_do_not_agree: 73 | push _address_sizes_do_not_agree 74 | jmp error_with_source 75 | disallowed_combination_of_registers: 76 | push _disallowed_combination_of_registers 77 | jmp error_with_source 78 | long_immediate_not_encodable: 79 | push _long_immediate_not_encodable 80 | jmp error_with_source 81 | relative_jump_out_of_range: 82 | push _relative_jump_out_of_range 83 | jmp error_with_source 84 | invalid_expression: 85 | push _invalid_expression 86 | jmp error_with_source 87 | invalid_address: 88 | push _invalid_address 89 | jmp error_with_source 90 | invalid_value: 91 | push _invalid_value 92 | jmp error_with_source 93 | value_out_of_range: 94 | push _value_out_of_range 95 | jmp error_with_source 96 | undefined_symbol: 97 | mov edi,message 98 | mov esi,_undefined_symbol 99 | call copy_asciiz 100 | push message 101 | cmp [error_info],0 102 | je error_with_source 103 | mov esi,[error_info] 104 | mov esi,[esi+24] 105 | or esi,esi 106 | jz error_with_source 107 | mov byte [edi-1],20h 108 | call write_quoted_symbol_name 109 | jmp error_with_source 110 | copy_asciiz: 111 | lods byte [esi] 112 | stos byte [edi] 113 | test al,al 114 | jnz copy_asciiz 115 | ret 116 | write_quoted_symbol_name: 117 | mov al,27h 118 | stosb 119 | movzx ecx,byte [esi-1] 120 | rep movs byte [edi],[esi] 121 | mov ax,27h 122 | stosw 123 | ret 124 | symbol_out_of_scope: 125 | mov edi,message 126 | mov esi,_symbol_out_of_scope_1 127 | call copy_asciiz 128 | cmp [error_info],0 129 | je finish_symbol_out_of_scope_message 130 | mov esi,[error_info] 131 | mov esi,[esi+24] 132 | or esi,esi 133 | jz finish_symbol_out_of_scope_message 134 | mov byte [edi-1],20h 135 | call write_quoted_symbol_name 136 | finish_symbol_out_of_scope_message: 137 | mov byte [edi-1],20h 138 | mov esi,_symbol_out_of_scope_2 139 | call copy_asciiz 140 | push message 141 | jmp error_with_source 142 | invalid_use_of_symbol: 143 | push _invalid_use_of_symbol 144 | jmp error_with_source 145 | name_too_long: 146 | push _name_too_long 147 | jmp error_with_source 148 | invalid_name: 149 | push _invalid_name 150 | jmp error_with_source 151 | reserved_word_used_as_symbol: 152 | push _reserved_word_used_as_symbol 153 | jmp error_with_source 154 | symbol_already_defined: 155 | push _symbol_already_defined 156 | jmp error_with_source 157 | missing_end_quote: 158 | push _missing_end_quote 159 | jmp error_with_source 160 | missing_end_directive: 161 | push _missing_end_directive 162 | jmp error_with_source 163 | unexpected_instruction: 164 | push _unexpected_instruction 165 | jmp error_with_source 166 | extra_characters_on_line: 167 | push _extra_characters_on_line 168 | jmp error_with_source 169 | section_not_aligned_enough: 170 | push _section_not_aligned_enough 171 | jmp error_with_source 172 | setting_already_specified: 173 | push _setting_already_specified 174 | jmp error_with_source 175 | data_already_defined: 176 | push _data_already_defined 177 | jmp error_with_source 178 | too_many_repeats: 179 | push _too_many_repeats 180 | jmp error_with_source 181 | assertion_failed: 182 | push _assertion_failed 183 | jmp error_with_source 184 | invoked_error: 185 | push _invoked_error 186 | error_with_source: 187 | cmp [symbols_file],0 188 | je assembler_error 189 | call dump_preprocessed_source 190 | call restore_preprocessed_source 191 | jmp assembler_error 192 | -------------------------------------------------------------------------------- /INCLUDE/WIN64WX.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win64 programming headers (WideChar) 3 | 4 | include 'win64w.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro invoke proc,[arg] 10 | \{ \common fastcall [proc],arg \} 11 | macro fastcall proc,[arg] 12 | \{ \common \local list,counter,flags,outer_frame,nested_frame,..close_nest 13 | match =current@frame,current@frame \\{ 14 | frame 15 | define outer_frame \\} 16 | define counter 17 | define list 18 | flags = 0 19 | \forward \local param,nested,isfloat,..next 20 | match any,counter \\{ list equ list, \\} 21 | counter equ counter+1 22 | define param arg 23 | define nested 24 | isfloat = 0 25 | match =invoke statement,param \\{ 26 | nested equ param 27 | define param \\} 28 | match =fastcall statement,param \\{ 29 | nested equ param 30 | define param \\} 31 | match =float =invoke statement,param \\{ 32 | define nested invoke statement 33 | define param 34 | isfloat = 1 \\} 35 | match =float =fastcall statement,param \\{ 36 | define nested fastcall statement 37 | define param 38 | isfloat = 1 \\} 39 | match statement,nested \\{ 40 | match =nested_frame,nested_frame \\\{ 41 | frame 42 | define nested_frame \\\} 43 | allow_nesting 44 | statement 45 | purge invoke_fastcall 46 | if counter > 4 47 | if isfloat 48 | movq [rsp+size@frame+(counter-1)*8],xmm0 49 | else 50 | mov [rsp+size@frame+(counter-1)*8],rax 51 | end if 52 | else 53 | flags = flags or 1 shl (counter-1) 54 | if isfloat 55 | flags = flags or 1 shl (4+counter-1) 56 | end if 57 | if ..close_nest > ..next 58 | if float 59 | movq [rsp+size@frame+(counter-1)*8],xmm0 60 | else 61 | mov [rsp+size@frame+(counter-1)*8],rax 62 | end if 63 | else 64 | flags = flags or 1 shl (8+counter-1) 65 | end if 66 | end if 67 | ..next: \\} 68 | list equ list 69 | \common ..close_nest: 70 | match ,nested_frame \\{ endf \\} 71 | if flags and 1 72 | if flags and 1 shl 4 73 | if ~ flags and 1 shl 8 74 | movq xmm0,[rsp] 75 | end if 76 | else 77 | if flags and 1 shl 8 78 | mov rcx,rax 79 | else 80 | mov rcx,[rsp] 81 | end if 82 | end if 83 | end if 84 | if flags and 1 shl 1 85 | if flags and 1 shl (4+1) 86 | if flags and 1 shl (8+1) 87 | movq xmm1,xmm0 88 | else 89 | movq xmm1,[rsp+8] 90 | end if 91 | else 92 | if flags and 1 shl (8+1) 93 | mov rdx,rax 94 | else 95 | mov rdx,[rsp+8] 96 | end if 97 | end if 98 | end if 99 | if flags and 1 shl 2 100 | if flags and 1 shl (4+2) 101 | if flags and 1 shl (8+2) 102 | movq xmm2,xmm0 103 | else 104 | movq xmm2,[rsp+2*8] 105 | end if 106 | else 107 | if flags and 1 shl (8+2) 108 | mov r8,rax 109 | else 110 | mov r8,[rsp+2*8] 111 | end if 112 | end if 113 | end if 114 | if flags and 1 shl 3 115 | if flags and 1 shl (4+3) 116 | if flags and 1 shl (8+3) 117 | movq xmm3,xmm0 118 | else 119 | movq xmm3,[rsp+3*8] 120 | end if 121 | else 122 | if flags and 1 shl (8+3) 123 | mov r9,rax 124 | else 125 | mov r9,[rsp+3*8] 126 | end if 127 | end if 128 | end if 129 | match args,list \\{ fastcall proc,args \\} 130 | match ,list \\{ fastcall proc \\} 131 | match ,outer_frame \\{ endf \\} \} } 132 | 133 | allow_nesting 134 | 135 | macro import lib,[functions] 136 | { common macro import_#lib \{ import lib,functions \} } 137 | 138 | macro api [functions] 139 | { common macro all_api \{ all_api 140 | api functions \} } 141 | macro all_api {} 142 | 143 | include 'api/kernel32.inc' 144 | include 'api/user32.inc' 145 | include 'api/gdi32.inc' 146 | include 'api/advapi32.inc' 147 | include 'api/comctl32.inc' 148 | include 'api/comdlg32.inc' 149 | include 'api/shell32.inc' 150 | include 'api/wsock32.inc' 151 | 152 | purge import,api 153 | 154 | macro .data { section '.data' data readable writeable } 155 | macro .code { 156 | section '.text' code readable executable 157 | entry $ 158 | sub rsp,8 159 | local main,code 160 | entry equ main 161 | if main <> code 162 | jmp main 163 | end if 164 | code: } 165 | 166 | macro .end value 167 | { 168 | label entry at value 169 | 170 | section '.idata' import data readable writeable 171 | 172 | library kernel32,'KERNEL32.DLL',\ 173 | user32,'USER32.DLL',\ 174 | gdi32,'GDI32.DLL',\ 175 | advapi32,'ADVAPI32.DLL',\ 176 | comctl32,'COMCTL32.DLL',\ 177 | comdlg32,'COMDLG32.DLL',\ 178 | shell32,'SHELL32.DLL',\ 179 | wsock32,'WSOCK32.DLL' 180 | 181 | import_kernel32 182 | import_user32 183 | import_gdi32 184 | import_advapi32 185 | import_comctl32 186 | import_comdlg32 187 | import_shell32 188 | import_wsock32 189 | 190 | all_api 191 | } 192 | 193 | virtual at 0 194 | inc ax 195 | if $=1 196 | detected_16bit = 1 197 | else 198 | detected_16bit = 0 199 | end if 200 | end virtual 201 | 202 | if detected_16bit 203 | format PE64 GUI 5.0 204 | end if 205 | -------------------------------------------------------------------------------- /INCLUDE/WIN64AX.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win64 programming headers (ASCII) 3 | 4 | include 'win64a.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro invoke proc,[arg] 10 | \{ \common fastcall [proc],arg \} 11 | macro fastcall proc,[arg] 12 | \{ \common \local list,counter,flags,outer_frame,nested_frame,..close_nest 13 | match =current@frame,current@frame \\{ 14 | frame 15 | define outer_frame \\} 16 | define counter 17 | define list 18 | flags = 0 19 | \forward \local param,nested,isfloat,..next 20 | match any,counter \\{ list equ list, \\} 21 | counter equ counter+1 22 | define param arg 23 | define nested 24 | isfloat = 0 25 | match =invoke statement,param \\{ 26 | nested equ param 27 | define param \\} 28 | match =fastcall statement,param \\{ 29 | nested equ param 30 | define param \\} 31 | match =float =invoke statement,param \\{ 32 | define nested invoke statement 33 | define param 34 | isfloat = 1 \\} 35 | match =float =fastcall statement,param \\{ 36 | define nested fastcall statement 37 | define param 38 | isfloat = 1 \\} 39 | match statement,nested \\{ 40 | match =nested_frame,nested_frame \\\{ 41 | frame 42 | define nested_frame \\\} 43 | allow_nesting 44 | statement 45 | purge invoke_fastcall 46 | if counter > 4 47 | if isfloat 48 | movq [rsp+size@frame+(counter-1)*8],xmm0 49 | else 50 | mov [rsp+size@frame+(counter-1)*8],rax 51 | end if 52 | else 53 | flags = flags or 1 shl (counter-1) 54 | if isfloat 55 | flags = flags or 1 shl (4+counter-1) 56 | end if 57 | if ..close_nest > ..next 58 | if float 59 | movq [rsp+size@frame+(counter-1)*8],xmm0 60 | else 61 | mov [rsp+size@frame+(counter-1)*8],rax 62 | end if 63 | else 64 | flags = flags or 1 shl (8+counter-1) 65 | end if 66 | end if 67 | ..next: \\} 68 | list equ list 69 | \common ..close_nest: 70 | match ,nested_frame \\{ endf \\} 71 | if flags and 1 72 | if flags and 1 shl 4 73 | if ~ flags and 1 shl 8 74 | movq xmm0,[rsp] 75 | end if 76 | else 77 | if flags and 1 shl 8 78 | mov rcx,rax 79 | else 80 | mov rcx,[rsp] 81 | end if 82 | end if 83 | end if 84 | if flags and 1 shl 1 85 | if flags and 1 shl (4+1) 86 | if flags and 1 shl (8+1) 87 | movq xmm1,xmm0 88 | else 89 | movq xmm1,[rsp+8] 90 | end if 91 | else 92 | if flags and 1 shl (8+1) 93 | mov rdx,rax 94 | else 95 | mov rdx,[rsp+8] 96 | end if 97 | end if 98 | end if 99 | if flags and 1 shl 2 100 | if flags and 1 shl (4+2) 101 | if flags and 1 shl (8+2) 102 | movq xmm2,xmm0 103 | else 104 | movq xmm2,[rsp+2*8] 105 | end if 106 | else 107 | if flags and 1 shl (8+2) 108 | mov r8,rax 109 | else 110 | mov r8,[rsp+2*8] 111 | end if 112 | end if 113 | end if 114 | if flags and 1 shl 3 115 | if flags and 1 shl (4+3) 116 | if flags and 1 shl (8+3) 117 | movq xmm3,xmm0 118 | else 119 | movq xmm3,[rsp+3*8] 120 | end if 121 | else 122 | if flags and 1 shl (8+3) 123 | mov r9,rax 124 | else 125 | mov r9,[rsp+3*8] 126 | end if 127 | end if 128 | end if 129 | match args,list \\{ fastcall proc,args \\} 130 | match ,list \\{ fastcall proc \\} 131 | match ,outer_frame \\{ endf \\} \} } 132 | 133 | allow_nesting 134 | 135 | macro import lib,[functions] 136 | { common macro import_#lib \{ import lib,functions \} } 137 | 138 | macro api [functions] 139 | { common macro all_api \{ all_api 140 | api functions \} } 141 | macro all_api {} 142 | 143 | include 'api/kernel32.inc' 144 | include 'api/user32.inc' 145 | include 'api/gdi32.inc' 146 | include 'api/advapi32.inc' 147 | include 'api/comctl32.inc' 148 | include 'api/comdlg32.inc' 149 | include 'api/shell32.inc' 150 | include 'api/wsock32.inc' 151 | 152 | purge import,api 153 | 154 | macro .data { section '.data' data readable writeable } 155 | 156 | macro .code { 157 | section '.text' code readable executable 158 | entry $ 159 | sub rsp,8 160 | local main,code 161 | entry equ main 162 | if main <> code 163 | jmp main 164 | end if 165 | code: } 166 | 167 | macro .end value 168 | { 169 | label entry at value 170 | 171 | section '.idata' import data readable writeable 172 | 173 | library kernel32,'KERNEL32.DLL',\ 174 | user32,'USER32.DLL',\ 175 | gdi32,'GDI32.DLL',\ 176 | advapi32,'ADVAPI32.DLL',\ 177 | comctl32,'COMCTL32.DLL',\ 178 | comdlg32,'COMDLG32.DLL',\ 179 | shell32,'SHELL32.DLL',\ 180 | wsock32,'WSOCK32.DLL' 181 | 182 | import_kernel32 183 | import_user32 184 | import_gdi32 185 | import_advapi32 186 | import_comctl32 187 | import_comdlg32 188 | import_shell32 189 | import_wsock32 190 | 191 | all_api 192 | } 193 | 194 | virtual at 0 195 | inc ax 196 | if $=1 197 | detected_16bit = 1 198 | else 199 | detected_16bit = 0 200 | end if 201 | end virtual 202 | 203 | if detected_16bit 204 | format PE64 GUI 5.0 205 | end if 206 | -------------------------------------------------------------------------------- /INCLUDE/WIN32AXP.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win32 programming headers with parameters count checking (ASCII) 3 | 4 | include 'win32a.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro pushd value 10 | \{ match ,value \\{ 11 | pushx equ \\} 12 | match =pushx =invoke proc,pushx value \\{ 13 | allow_nesting 14 | invoke proc 15 | purge pushd,invoke,stdcall,cinvoke,ccall 16 | push eax 17 | pushx equ \\} 18 | match =pushx =stdcall proc,pushx value \\{ 19 | allow_nesting 20 | stdcall proc 21 | purge pushd,invoke,stdcall,cinvoke,ccall 22 | push eax 23 | pushx equ \\} 24 | match =pushx =cinvoke proc,pushx value \\{ 25 | allow_nesting 26 | cinvoke proc 27 | purge pushd,invoke,stdcall,cinvoke,ccall 28 | push eax 29 | pushx equ \\} 30 | match =pushx =ccall proc,pushx value \\{ 31 | allow_nesting 32 | ccall proc 33 | purge pushd,invoke,stdcall,cinvoke,ccall 34 | push eax 35 | pushx equ \\} 36 | match =pushx,pushx \\{ 37 | pushd 38 | pushx equ \\} 39 | restore pushx \} 40 | macro invoke proc,[arg] 41 | \{ \common count@stdcall = 0 42 | if ~ arg eq 43 | \forward count@stdcall = count@stdcall+1 44 | match =double value, arg \\{ count@stdcall = count@stdcall+1 \\} 45 | \common end if 46 | if proc eqtype 0 & defined proc \# % & count@stdcall <> proc \# % 47 | display "Error: invalid count of parameters for ",\`proc,".",0Dh,0Ah 48 | assert 0 49 | end if 50 | \reverse pushd 51 | \common call [proc] \} 52 | macro stdcall proc,[arg] 53 | \{ \common count@stdcall = 0 54 | if ~ arg eq 55 | \forward count@stdcall = count@stdcall+1 56 | match =double value, arg \\{ count@stdcall = count@stdcall+1 \\} 57 | \common end if 58 | if proc eqtype 0 & defined proc \# % & count@stdcall <> proc \# % 59 | display "Error: invalid count of parameters for ",\`proc,".",0Dh,0Ah 60 | assert 0 61 | end if 62 | \reverse pushd 63 | \common call proc \} 64 | macro cinvoke proc,[arg] 65 | \{ \common \local size 66 | size = 0 67 | if ~ arg eq 68 | \reverse pushd 69 | size = size+4 70 | match =double any,arg \\{ size = size+4 \\} 71 | \common end if 72 | call [proc] 73 | if size 74 | add esp,size 75 | end if \} 76 | macro ccall proc,[arg] 77 | \{ \common \local size 78 | size = 0 79 | if ~ arg eq 80 | \reverse pushd 81 | size = size+4 82 | match =double any,arg \\{ size = size+4 \\} 83 | \common end if 84 | call proc 85 | if size 86 | add esp,size 87 | end if \} } 88 | 89 | macro pushd value 90 | { match first=,more, value \{ \local ..continue 91 | call ..continue 92 | db value,0 93 | ..continue: 94 | pushd equ \} 95 | match pushd =addr var,pushd value \{ \local ..opcode,..address 96 | if +var relativeto 0 | +var relativeto $ 97 | push var 98 | else 99 | lea edx,[var] 100 | push edx 101 | end if 102 | pushd equ \} 103 | match pushd =double [var],pushd value \{ 104 | push dword [var+4] 105 | push dword [var] 106 | pushd equ \} 107 | match pushd =double =ptr var,pushd value \{ 108 | push dword [var+4] 109 | push dword [var] 110 | pushd equ \} 111 | match pushd =double num,pushd value \{ \local ..high,..low 112 | virtual at 0 113 | dq num 114 | load ..low dword from 0 115 | load ..high dword from 4 116 | end virtual 117 | push ..high 118 | push ..low 119 | pushd equ \} 120 | match pushd,pushd \{ \local ..continue 121 | if value eqtype '' 122 | call ..continue 123 | db value,0 124 | ..continue: 125 | else 126 | push value 127 | end if 128 | pushd equ \} 129 | restore pushd } 130 | 131 | allow_nesting 132 | 133 | include 'pcount/kernel32.inc' 134 | include 'pcount/user32.inc' 135 | include 'pcount/gdi32.inc' 136 | include 'pcount/advapi32.inc' 137 | include 'pcount/comctl32.inc' 138 | include 'pcount/comdlg32.inc' 139 | include 'pcount/shell32.inc' 140 | include 'pcount/wsock32.inc' 141 | 142 | macro import lib,[functions] 143 | { common macro import_#lib \{ import lib,functions \} } 144 | 145 | macro api [functions] 146 | { common macro all_api \{ all_api 147 | api functions \} } 148 | macro all_api {} 149 | 150 | include 'api/kernel32.inc' 151 | include 'api/user32.inc' 152 | include 'api/gdi32.inc' 153 | include 'api/advapi32.inc' 154 | include 'api/comctl32.inc' 155 | include 'api/comdlg32.inc' 156 | include 'api/shell32.inc' 157 | include 'api/wsock32.inc' 158 | 159 | purge import,api 160 | 161 | macro .data { section '.data' data readable writeable } 162 | 163 | macro .code { section '.text' code readable executable } 164 | 165 | macro .end label 166 | { 167 | entry label 168 | 169 | section '.idata' import data readable writeable 170 | 171 | library kernel32,'KERNEL32.DLL',\ 172 | user32,'USER32.DLL',\ 173 | gdi32,'GDI32.DLL',\ 174 | advapi32,'ADVAPI32.DLL',\ 175 | comctl32,'COMCTL32.DLL',\ 176 | comdlg32,'COMDLG32.DLL',\ 177 | shell32,'SHELL32.DLL',\ 178 | wsock32,'WSOCK32.DLL' 179 | 180 | import_kernel32 181 | import_user32 182 | import_gdi32 183 | import_advapi32 184 | import_comctl32 185 | import_comdlg32 186 | import_shell32 187 | import_wsock32 188 | 189 | all_api 190 | } 191 | 192 | virtual at 0 193 | xchg eax,eax 194 | detected_16bit = $-1 195 | end virtual 196 | 197 | if detected_16bit 198 | format PE GUI 4.0 199 | end if 200 | -------------------------------------------------------------------------------- /INCLUDE/WIN32WXP.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win32 programming headers with parameters count checking (WideChar) 3 | 4 | include 'win32w.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro pushd value 10 | \{ match ,value \\{ 11 | pushx equ \\} 12 | match =pushx =invoke proc,pushx value \\{ 13 | allow_nesting 14 | invoke proc 15 | purge pushd,invoke,stdcall,cinvoke,ccall 16 | push eax 17 | pushx equ \\} 18 | match =pushx =stdcall proc,pushx value \\{ 19 | allow_nesting 20 | stdcall proc 21 | purge pushd,invoke,stdcall,cinvoke,ccall 22 | push eax 23 | pushx equ \\} 24 | match =pushx =cinvoke proc,pushx value \\{ 25 | allow_nesting 26 | cinvoke proc 27 | purge pushd,invoke,stdcall,cinvoke,ccall 28 | push eax 29 | pushx equ \\} 30 | match =pushx =ccall proc,pushx value \\{ 31 | allow_nesting 32 | ccall proc 33 | purge pushd,invoke,stdcall,cinvoke,ccall 34 | push eax 35 | pushx equ \\} 36 | match =pushx,pushx \\{ 37 | pushd 38 | pushx equ \\} 39 | restore pushx \} 40 | macro invoke proc,[arg] 41 | \{ \common count@stdcall = 0 42 | if ~ arg eq 43 | \forward count@stdcall = count@stdcall+1 44 | match =double value, arg \\{ count@stdcall = count@stdcall+1 \\} 45 | \common end if 46 | if proc eqtype 0 & defined proc \# % & count@stdcall <> proc \# % 47 | display "Error: invalid count of parameters for ",\`proc,".",0Dh,0Ah 48 | assert 0 49 | end if 50 | \reverse pushd 51 | \common call [proc] \} 52 | macro stdcall proc,[arg] 53 | \{ \common count@stdcall = 0 54 | if ~ arg eq 55 | \forward count@stdcall = count@stdcall+1 56 | match =double value, arg \\{ count@stdcall = count@stdcall+1 \\} 57 | \common end if 58 | if proc eqtype 0 & defined proc \# % & count@stdcall <> proc \# % 59 | display "Error: invalid count of parameters for ",\`proc,".",0Dh,0Ah 60 | assert 0 61 | end if 62 | \reverse pushd 63 | \common call proc \} 64 | macro cinvoke proc,[arg] 65 | \{ \common \local size 66 | size = 0 67 | if ~ arg eq 68 | \reverse pushd 69 | size = size+4 70 | match =double any,arg \\{ size = size+4 \\} 71 | \common end if 72 | call [proc] 73 | if size 74 | add esp,size 75 | end if \} 76 | macro ccall proc,[arg] 77 | \{ \common \local size 78 | size = 0 79 | if ~ arg eq 80 | \reverse pushd 81 | size = size+4 82 | match =double any,arg \\{ size = size+4 \\} 83 | \common end if 84 | call proc 85 | if size 86 | add esp,size 87 | end if \} } 88 | 89 | macro pushd value 90 | { match first=,more, value \{ \local ..continue 91 | times 1 - (rva $ and 1) nop 92 | call ..continue 93 | du value,0 94 | ..continue: 95 | pushd equ \} 96 | match pushd =addr var,pushd value \{ \local ..opcode,..address 97 | if +var relativeto 0 | +var relativeto $ 98 | push var 99 | else 100 | lea edx,[var] 101 | push edx 102 | end if 103 | pushd equ \} 104 | match pushd =double [var],pushd value \{ 105 | push dword [var+4] 106 | push dword [var] 107 | pushd equ \} 108 | match pushd =double =ptr var,pushd value \{ 109 | push dword [var+4] 110 | push dword [var] 111 | pushd equ \} 112 | match pushd =double num,pushd value \{ \local ..high,..low 113 | virtual at 0 114 | dq num 115 | load ..low dword from 0 116 | load ..high dword from 4 117 | end virtual 118 | push ..high 119 | push ..low 120 | pushd equ \} 121 | match pushd,pushd \{ \local ..continue 122 | if value eqtype '' 123 | times 1 - (rva $ and 1) nop 124 | call ..continue 125 | du value,0 126 | ..continue: 127 | else 128 | push value 129 | end if 130 | pushd equ \} 131 | restore pushd } 132 | 133 | allow_nesting 134 | 135 | include 'pcount/kernel32.inc' 136 | include 'pcount/user32.inc' 137 | include 'pcount/gdi32.inc' 138 | include 'pcount/advapi32.inc' 139 | include 'pcount/comctl32.inc' 140 | include 'pcount/comdlg32.inc' 141 | include 'pcount/shell32.inc' 142 | include 'pcount/wsock32.inc' 143 | 144 | macro import lib,[functions] 145 | { common macro import_#lib \{ import lib,functions \} } 146 | 147 | macro api [functions] 148 | { common macro all_api \{ all_api 149 | api functions \} } 150 | macro all_api {} 151 | 152 | include 'api/kernel32.inc' 153 | include 'api/user32.inc' 154 | include 'api/gdi32.inc' 155 | include 'api/advapi32.inc' 156 | include 'api/comctl32.inc' 157 | include 'api/comdlg32.inc' 158 | include 'api/shell32.inc' 159 | include 'api/wsock32.inc' 160 | 161 | purge import,api 162 | 163 | macro .data { section '.data' data readable writeable } 164 | 165 | macro .code { section '.text' code readable executable } 166 | 167 | macro .end label 168 | { 169 | entry label 170 | 171 | section '.idata' import data readable writeable 172 | 173 | library kernel32,'KERNEL32.DLL',\ 174 | user32,'USER32.DLL',\ 175 | gdi32,'GDI32.DLL',\ 176 | advapi32,'ADVAPI32.DLL',\ 177 | comctl32,'COMCTL32.DLL',\ 178 | comdlg32,'COMDLG32.DLL',\ 179 | shell32,'SHELL32.DLL',\ 180 | wsock32,'WSOCK32.DLL' 181 | 182 | import_kernel32 183 | import_user32 184 | import_gdi32 185 | import_advapi32 186 | import_comctl32 187 | import_comdlg32 188 | import_shell32 189 | import_wsock32 190 | 191 | all_api 192 | } 193 | 194 | virtual at 0 195 | xchg eax,eax 196 | detected_16bit = $-1 197 | end virtual 198 | 199 | if detected_16bit 200 | format PE GUI 4.0 201 | end if 202 | -------------------------------------------------------------------------------- /EXAMPLES/MINIPAD/MINIPAD.ASM: -------------------------------------------------------------------------------- 1 | 2 | ; Simple text editor - fasm example program 3 | 4 | format PE GUI 4.0 5 | entry start 6 | 7 | include 'win32a.inc' 8 | 9 | IDR_ICON = 17 10 | IDR_MENU = 37 11 | 12 | IDM_NEW = 101 13 | IDM_EXIT = 102 14 | IDM_ABOUT = 901 15 | 16 | section '.text' code readable executable 17 | 18 | start: 19 | 20 | invoke GetModuleHandle,0 21 | mov [wc.hInstance],eax 22 | 23 | invoke LoadIcon,eax,IDR_ICON 24 | mov [wc.hIcon],eax 25 | invoke LoadCursor,0,IDC_ARROW 26 | mov [wc.hCursor],eax 27 | invoke RegisterClass,wc 28 | test eax,eax 29 | jz error 30 | 31 | invoke LoadMenu,[wc.hInstance],IDR_MENU 32 | invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW,144,128,256,256,NULL,eax,[wc.hInstance],NULL 33 | test eax,eax 34 | jz error 35 | 36 | msg_loop: 37 | invoke GetMessage,msg,NULL,0,0 38 | cmp eax,1 39 | jb end_loop 40 | jne msg_loop 41 | invoke TranslateMessage,msg 42 | invoke DispatchMessage,msg 43 | jmp msg_loop 44 | 45 | error: 46 | invoke MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK 47 | 48 | end_loop: 49 | invoke ExitProcess,[msg.wParam] 50 | 51 | proc WindowProc hwnd,wmsg,wparam,lparam 52 | push ebx esi edi 53 | mov eax,[wmsg] 54 | cmp eax,WM_CREATE 55 | je .wmcreate 56 | cmp eax,WM_SIZE 57 | je .wmsize 58 | cmp eax,WM_SETFOCUS 59 | je .wmsetfocus 60 | cmp eax,WM_COMMAND 61 | je .wmcommand 62 | cmp eax,WM_DESTROY 63 | je .wmdestroy 64 | .defwndproc: 65 | invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] 66 | jmp .finish 67 | .wmcreate: 68 | invoke GetClientRect,[hwnd],client 69 | invoke CreateWindowEx,WS_EX_CLIENTEDGE,_edit,0,WS_VISIBLE+WS_CHILD+WS_HSCROLL+WS_VSCROLL+ES_AUTOHSCROLL+ES_AUTOVSCROLL+ES_MULTILINE,[client.left],[client.top],[client.right],[client.bottom],[hwnd],0,[wc.hInstance],NULL 70 | or eax,eax 71 | jz .failed 72 | mov [edithwnd],eax 73 | invoke CreateFont,16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL 74 | or eax,eax 75 | jz .failed 76 | mov [editfont],eax 77 | invoke SendMessage,[edithwnd],WM_SETFONT,eax,FALSE 78 | xor eax,eax 79 | jmp .finish 80 | .failed: 81 | or eax,-1 82 | jmp .finish 83 | .wmsize: 84 | invoke GetClientRect,[hwnd],client 85 | invoke MoveWindow,[edithwnd],[client.left],[client.top],[client.right],[client.bottom],TRUE 86 | xor eax,eax 87 | jmp .finish 88 | .wmsetfocus: 89 | invoke SetFocus,[edithwnd] 90 | xor eax,eax 91 | jmp .finish 92 | .wmcommand: 93 | mov eax,[wparam] 94 | and eax,0FFFFh 95 | cmp eax,IDM_NEW 96 | je .new 97 | cmp eax,IDM_ABOUT 98 | je .about 99 | cmp eax,IDM_EXIT 100 | je .wmdestroy 101 | jmp .defwndproc 102 | .new: 103 | invoke SendMessage,[edithwnd],WM_SETTEXT,0,0 104 | jmp .finish 105 | .about: 106 | invoke MessageBox,[hwnd],_about_text,_about_title,MB_OK 107 | jmp .finish 108 | .wmdestroy: 109 | invoke DeleteObject,[editfont] 110 | invoke PostQuitMessage,0 111 | xor eax,eax 112 | .finish: 113 | pop edi esi ebx 114 | ret 115 | endp 116 | 117 | section '.data' data readable writeable 118 | 119 | _title TCHAR 'MiniPad',0 120 | _about_title TCHAR 'About MiniPad',0 121 | _about_text TCHAR 'This is Win32 example program created with flat assembler.',0 122 | _error TCHAR 'Startup failed.',0 123 | 124 | _class TCHAR 'MINIPAD32',0 125 | _edit TCHAR 'EDIT',0 126 | 127 | wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class 128 | 129 | edithwnd dd ? 130 | editfont dd ? 131 | 132 | msg MSG 133 | client RECT 134 | 135 | section '.idata' import data readable writeable 136 | 137 | library kernel,'KERNEL32.DLL',\ 138 | user,'USER32.DLL',\ 139 | gdi,'GDI32.DLL' 140 | 141 | import kernel,\ 142 | GetModuleHandle,'GetModuleHandleA',\ 143 | ExitProcess,'ExitProcess' 144 | 145 | import user,\ 146 | RegisterClass,'RegisterClassA',\ 147 | CreateWindowEx,'CreateWindowExA',\ 148 | DefWindowProc,'DefWindowProcA',\ 149 | SetWindowLong,'SetWindowLongA',\ 150 | RedrawWindow,'RedrawWindow',\ 151 | GetMessage,'GetMessageA',\ 152 | TranslateMessage,'TranslateMessage',\ 153 | DispatchMessage,'DispatchMessageA',\ 154 | SendMessage,'SendMessageA',\ 155 | LoadCursor,'LoadCursorA',\ 156 | LoadIcon,'LoadIconA',\ 157 | LoadMenu,'LoadMenuA',\ 158 | GetClientRect,'GetClientRect',\ 159 | MoveWindow,'MoveWindow',\ 160 | SetFocus,'SetFocus',\ 161 | MessageBox,'MessageBoxA',\ 162 | PostQuitMessage,'PostQuitMessage' 163 | 164 | import gdi,\ 165 | CreateFont,'CreateFontA',\ 166 | DeleteObject,'DeleteObject' 167 | 168 | section '.rsrc' resource data readable 169 | 170 | ; resource directory 171 | 172 | directory RT_MENU,menus,\ 173 | RT_ICON,icons,\ 174 | RT_GROUP_ICON,group_icons,\ 175 | RT_VERSION,versions 176 | 177 | ; resource subdirectories 178 | 179 | resource menus,\ 180 | IDR_MENU,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu 181 | 182 | resource icons,\ 183 | 1,LANG_NEUTRAL,icon_data 184 | 185 | resource group_icons,\ 186 | IDR_ICON,LANG_NEUTRAL,main_icon 187 | 188 | resource versions,\ 189 | 1,LANG_NEUTRAL,version 190 | 191 | menu main_menu 192 | menuitem '&File',0,MFR_POPUP 193 | menuitem '&New',IDM_NEW 194 | menuseparator 195 | menuitem 'E&xit',IDM_EXIT,MFR_END 196 | menuitem '&Help',0,MFR_POPUP + MFR_END 197 | menuitem '&About...',IDM_ABOUT,MFR_END 198 | 199 | icon main_icon,icon_data,'minipad.ico' 200 | 201 | versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\ 202 | 'FileDescription','MiniPad - example program',\ 203 | 'LegalCopyright','No rights reserved.',\ 204 | 'FileVersion','1.0',\ 205 | 'ProductVersion','1.0',\ 206 | 'OriginalFilename','MINIPAD.EXE' 207 | -------------------------------------------------------------------------------- /INCLUDE/WIN64AXP.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win64 programming headers with parameters count checking (ASCII) 3 | 4 | include 'win64a.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro invoke proc,[arg] 10 | \{ \common fastcall [proc],arg \} 11 | macro fastcall proc,[arg] 12 | \{ \common \local list,counter,flags,outer_frame,nested_frame,..close_nest 13 | match =current@frame,current@frame \\{ 14 | frame 15 | define outer_frame \\} 16 | define counter 17 | define list 18 | flags = 0 19 | \forward \local param,nested,isfloat,..next 20 | match any,counter \\{ list equ list, \\} 21 | counter equ counter+1 22 | define param arg 23 | define nested 24 | isfloat = 0 25 | match =invoke statement,param \\{ 26 | nested equ param 27 | define param \\} 28 | match =fastcall statement,param \\{ 29 | nested equ param 30 | define param \\} 31 | match =float =invoke statement,param \\{ 32 | define nested invoke statement 33 | define param 34 | isfloat = 1 \\} 35 | match =float =fastcall statement,param \\{ 36 | define nested fastcall statement 37 | define param 38 | isfloat = 1 \\} 39 | match statement,nested \\{ 40 | match =nested_frame,nested_frame \\\{ 41 | frame 42 | define nested_frame \\\} 43 | allow_nesting 44 | statement 45 | purge invoke_fastcall 46 | if counter > 4 47 | if isfloat 48 | movq [rsp+size@frame+(counter-1)*8],xmm0 49 | else 50 | mov [rsp+size@frame+(counter-1)*8],rax 51 | end if 52 | else 53 | flags = flags or 1 shl (counter-1) 54 | if isfloat 55 | flags = flags or 1 shl (4+counter-1) 56 | end if 57 | if ..close_nest > ..next 58 | if float 59 | movq [rsp+size@frame+(counter-1)*8],xmm0 60 | else 61 | mov [rsp+size@frame+(counter-1)*8],rax 62 | end if 63 | else 64 | flags = flags or 1 shl (8+counter-1) 65 | end if 66 | end if 67 | ..next: \\} 68 | match any,param \\{ list equ list \\} 69 | \common ..close_nest: 70 | match ,nested_frame \\{ endf \\} 71 | if flags and 1 72 | if flags and 1 shl 4 73 | if ~ flags and 1 shl 8 74 | movq xmm0,[rsp] 75 | end if 76 | else 77 | if flags and 1 shl 8 78 | mov rcx,rax 79 | else 80 | mov rcx,[rsp] 81 | end if 82 | end if 83 | end if 84 | if flags and 1 shl 1 85 | if flags and 1 shl (4+1) 86 | if flags and 1 shl (8+1) 87 | movq xmm1,xmm0 88 | else 89 | movq xmm1,[rsp+8] 90 | end if 91 | else 92 | if flags and 1 shl (8+1) 93 | mov rdx,rax 94 | else 95 | mov rdx,[rsp+8] 96 | end if 97 | end if 98 | end if 99 | if flags and 1 shl 2 100 | if flags and 1 shl (4+2) 101 | if flags and 1 shl (8+2) 102 | movq xmm2,xmm0 103 | else 104 | movq xmm2,[rsp+2*8] 105 | end if 106 | else 107 | if flags and 1 shl (8+2) 108 | mov r8,rax 109 | else 110 | mov r8,[rsp+2*8] 111 | end if 112 | end if 113 | end if 114 | if flags and 1 shl 3 115 | if flags and 1 shl (4+3) 116 | if flags and 1 shl (8+3) 117 | movq xmm3,xmm0 118 | else 119 | movq xmm3,[rsp+3*8] 120 | end if 121 | else 122 | if flags and 1 shl (8+3) 123 | mov r9,rax 124 | else 125 | mov r9,[rsp+3*8] 126 | end if 127 | end if 128 | end if 129 | match args,list \\{ fastcall proc,args \\} 130 | match ,list \\{ fastcall proc 131 | define counter 0 \\} 132 | match ,outer_frame \\{ endf \\} 133 | proc@paramcheck equ proc 134 | match [name],proc \\{ define proc@paramcheck name \\} 135 | match name,proc@paramcheck \\{ if name eqtype 0 & defined name \\# % & counter <> name \\# % 136 | display "Error: invalid count of parameters for ",\\`name,".",0Dh,0Ah 137 | assert 0 138 | end if \\} \} } 139 | 140 | allow_nesting 141 | 142 | include 'pcount/kernel32.inc' 143 | include 'pcount/user32.inc' 144 | include 'pcount/gdi32.inc' 145 | include 'pcount/advapi32.inc' 146 | include 'pcount/comctl32.inc' 147 | include 'pcount/comdlg32.inc' 148 | include 'pcount/shell32.inc' 149 | include 'pcount/wsock32.inc' 150 | 151 | macro import lib,[functions] 152 | { common macro import_#lib \{ import lib,functions \} } 153 | 154 | macro api [functions] 155 | { common macro all_api \{ all_api 156 | api functions \} } 157 | macro all_api {} 158 | 159 | include 'api/kernel32.inc' 160 | include 'api/user32.inc' 161 | include 'api/gdi32.inc' 162 | include 'api/advapi32.inc' 163 | include 'api/comctl32.inc' 164 | include 'api/comdlg32.inc' 165 | include 'api/shell32.inc' 166 | include 'api/wsock32.inc' 167 | 168 | purge import,api 169 | 170 | macro .data { section '.data' data readable writeable } 171 | 172 | macro .code { 173 | section '.text' code readable executable 174 | entry $ 175 | sub rsp,8 176 | local main,code 177 | entry equ main 178 | if main <> code 179 | jmp main 180 | end if 181 | code: } 182 | 183 | macro .end value 184 | { 185 | label entry at value 186 | 187 | section '.idata' import data readable writeable 188 | 189 | library kernel32,'KERNEL32.DLL',\ 190 | user32,'USER32.DLL',\ 191 | gdi32,'GDI32.DLL',\ 192 | advapi32,'ADVAPI32.DLL',\ 193 | comctl32,'COMCTL32.DLL',\ 194 | comdlg32,'COMDLG32.DLL',\ 195 | shell32,'SHELL32.DLL',\ 196 | wsock32,'WSOCK32.DLL' 197 | 198 | import_kernel32 199 | import_user32 200 | import_gdi32 201 | import_advapi32 202 | import_comctl32 203 | import_comdlg32 204 | import_shell32 205 | import_wsock32 206 | 207 | all_api 208 | } 209 | 210 | virtual at 0 211 | inc ax 212 | if $=1 213 | detected_16bit = 1 214 | else 215 | detected_16bit = 0 216 | end if 217 | end virtual 218 | 219 | if detected_16bit 220 | format PE64 GUI 5.0 221 | end if 222 | -------------------------------------------------------------------------------- /INCLUDE/WIN64WXP.INC: -------------------------------------------------------------------------------- 1 | 2 | ; Extended Win64 programming headers with parameters count checking (WideChar) 3 | 4 | include 'win64w.inc' 5 | 6 | include 'macro/if.inc' 7 | 8 | macro allow_nesting 9 | { macro invoke proc,[arg] 10 | \{ \common fastcall [proc],arg \} 11 | macro fastcall proc,[arg] 12 | \{ \common \local list,counter,flags,outer_frame,nested_frame,..close_nest 13 | match =current@frame,current@frame \\{ 14 | frame 15 | define outer_frame \\} 16 | define counter 17 | define list 18 | flags = 0 19 | \forward \local param,nested,isfloat,..next 20 | match any,counter \\{ list equ list, \\} 21 | counter equ counter+1 22 | define param arg 23 | define nested 24 | isfloat = 0 25 | match =invoke statement,param \\{ 26 | nested equ param 27 | define param \\} 28 | match =fastcall statement,param \\{ 29 | nested equ param 30 | define param \\} 31 | match =float =invoke statement,param \\{ 32 | define nested invoke statement 33 | define param 34 | isfloat = 1 \\} 35 | match =float =fastcall statement,param \\{ 36 | define nested fastcall statement 37 | define param 38 | isfloat = 1 \\} 39 | match statement,nested \\{ 40 | match =nested_frame,nested_frame \\\{ 41 | frame 42 | define nested_frame \\\} 43 | allow_nesting 44 | statement 45 | purge invoke_fastcall 46 | if counter > 4 47 | if isfloat 48 | movq [rsp+size@frame+(counter-1)*8],xmm0 49 | else 50 | mov [rsp+size@frame+(counter-1)*8],rax 51 | end if 52 | else 53 | flags = flags or 1 shl (counter-1) 54 | if isfloat 55 | flags = flags or 1 shl (4+counter-1) 56 | end if 57 | if ..close_nest > ..next 58 | if float 59 | movq [rsp+size@frame+(counter-1)*8],xmm0 60 | else 61 | mov [rsp+size@frame+(counter-1)*8],rax 62 | end if 63 | else 64 | flags = flags or 1 shl (8+counter-1) 65 | end if 66 | end if 67 | ..next: \\} 68 | match any,param \\{ list equ list \\} 69 | \common ..close_nest: 70 | match ,nested_frame \\{ endf \\} 71 | if flags and 1 72 | if flags and 1 shl 4 73 | if ~ flags and 1 shl 8 74 | movq xmm0,[rsp] 75 | end if 76 | else 77 | if flags and 1 shl 8 78 | mov rcx,rax 79 | else 80 | mov rcx,[rsp] 81 | end if 82 | end if 83 | end if 84 | if flags and 1 shl 1 85 | if flags and 1 shl (4+1) 86 | if flags and 1 shl (8+1) 87 | movq xmm1,xmm0 88 | else 89 | movq xmm1,[rsp+8] 90 | end if 91 | else 92 | if flags and 1 shl (8+1) 93 | mov rdx,rax 94 | else 95 | mov rdx,[rsp+8] 96 | end if 97 | end if 98 | end if 99 | if flags and 1 shl 2 100 | if flags and 1 shl (4+2) 101 | if flags and 1 shl (8+2) 102 | movq xmm2,xmm0 103 | else 104 | movq xmm2,[rsp+2*8] 105 | end if 106 | else 107 | if flags and 1 shl (8+2) 108 | mov r8,rax 109 | else 110 | mov r8,[rsp+2*8] 111 | end if 112 | end if 113 | end if 114 | if flags and 1 shl 3 115 | if flags and 1 shl (4+3) 116 | if flags and 1 shl (8+3) 117 | movq xmm3,xmm0 118 | else 119 | movq xmm3,[rsp+3*8] 120 | end if 121 | else 122 | if flags and 1 shl (8+3) 123 | mov r9,rax 124 | else 125 | mov r9,[rsp+3*8] 126 | end if 127 | end if 128 | end if 129 | match args,list \\{ fastcall proc,args \\} 130 | match ,list \\{ fastcall proc 131 | define counter 0 \\} 132 | match ,outer_frame \\{ endf \\} 133 | proc@paramcheck equ proc 134 | match [name],proc \\{ define proc@paramcheck name \\} 135 | match name,proc@paramcheck \\{ if name eqtype 0 & defined name \\# % & counter <> name \\# % 136 | display "Error: invalid count of parameters for ",\\`name,".",0Dh,0Ah 137 | assert 0 138 | end if \\} \} } 139 | 140 | allow_nesting 141 | 142 | include 'pcount/kernel32.inc' 143 | include 'pcount/user32.inc' 144 | include 'pcount/gdi32.inc' 145 | include 'pcount/advapi32.inc' 146 | include 'pcount/comctl32.inc' 147 | include 'pcount/comdlg32.inc' 148 | include 'pcount/shell32.inc' 149 | include 'pcount/wsock32.inc' 150 | 151 | macro import lib,[functions] 152 | { common macro import_#lib \{ import lib,functions \} } 153 | 154 | macro api [functions] 155 | { common macro all_api \{ all_api 156 | api functions \} } 157 | macro all_api {} 158 | 159 | include 'api/kernel32.inc' 160 | include 'api/user32.inc' 161 | include 'api/gdi32.inc' 162 | include 'api/advapi32.inc' 163 | include 'api/comctl32.inc' 164 | include 'api/comdlg32.inc' 165 | include 'api/shell32.inc' 166 | include 'api/wsock32.inc' 167 | 168 | purge import,api 169 | 170 | macro .data { section '.data' data readable writeable } 171 | 172 | macro .code { 173 | section '.text' code readable executable 174 | entry $ 175 | sub rsp,8 176 | local main,code 177 | entry equ main 178 | if main <> code 179 | jmp main 180 | end if 181 | code: } 182 | 183 | macro .end value 184 | { 185 | label entry at value 186 | 187 | section '.idata' import data readable writeable 188 | 189 | library kernel32,'KERNEL32.DLL',\ 190 | user32,'USER32.DLL',\ 191 | gdi32,'GDI32.DLL',\ 192 | advapi32,'ADVAPI32.DLL',\ 193 | comctl32,'COMCTL32.DLL',\ 194 | comdlg32,'COMDLG32.DLL',\ 195 | shell32,'SHELL32.DLL',\ 196 | wsock32,'WSOCK32.DLL' 197 | 198 | import_kernel32 199 | import_user32 200 | import_gdi32 201 | import_advapi32 202 | import_comctl32 203 | import_comdlg32 204 | import_shell32 205 | import_wsock32 206 | 207 | all_api 208 | } 209 | 210 | virtual at 0 211 | inc ax 212 | if $=1 213 | detected_16bit = 1 214 | else 215 | detected_16bit = 0 216 | end if 217 | end virtual 218 | 219 | if detected_16bit 220 | format PE64 GUI 5.0 221 | end if 222 | --------------------------------------------------------------------------------