flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > preprocessor/ include confusion |
Author |
|
revolution 04 Apr 2020, 01:53
include should work perfectly fine in the way you say.
Show your code and we can help. |
|||
04 Apr 2020, 01:53 |
|
B.Dubious 04 Apr 2020, 02:07
I'm sure this will be embarrassing for me!
I'll paste the code below as I don't see a way to upload files, nor do I see a method to format. I've marked the relevant section which I saved out into a seperate file with //@start and //@end blocks... Sorry! I'm also struggling to workout how to deal with structs as you can probably see... I just simply yanked the data section out into the seperate file and saved the changes. When I went to build it failed on: mov [WindowClass.hInstance], rax in the .text section. If its relevant I'm building from the command line through a .bat file. If you could give some advice regarding the structs and the most appropriate way to set local aliases or whatever they're properly called. I'm still trying to grok rather a large proportion of the fundamentals. -------------------- Code: format PE64 entry main include 'fasm\INCLUDE\win64a.inc' ; include '.\main_data.asm' //@start This here is the section I wanted to store in main_data.asm section '.data' data readable writeable GlobalRunning db 0 struc draw_buffer BmpInfoHeader, PixelPtr, Width, Height { .BitmapInfoHeader dq BmpInfoHeader .PixelPointer dq PixelPtr .Width dq Width .Height dq Height } DrawBufferBMPInfoHeader BITMAPINFOHEADER GlobalDrawBuffer draw_buffer DrawBufferBMPInfoHeader,0,0,0 WindowClassName db "win32app",0 WindowTitle db "win32 Apllication",0 WindowRegErrorMessage db "Error encountered when registering window class: closing",0 WindowCreateErrorMessage db "Error encountered when creating window: closing",0 WindowClass WNDCLASSEX sizeof.WNDCLASSEX,0,Win32CallbackProc,0,0,0,0,0,COLOR_WINDOW,0,WindowClassName,0 Message MSG WindowHandle dq 0 //@end section '.text' code readable executable main: sub rsp,8 invoke GetModuleHandle,0 mov [WindowClass.hInstance], rax invoke LoadIcon,0,IDI_APPLICATION mov [WindowClass.hIcon],rax mov [WindowClass.hIconSm],rax invoke LoadCursor,0,IDC_ARROW mov [WindowClass.hCursor],rax invoke RegisterClassExA,WindowClass test rax, rax jz registration_error invoke CreateWindowExA,0,WindowClassName,WindowTitle, WS_VISIBLE+WS_OVERLAPPEDWINDOW,\ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0,0,[WindowClass.hInstance],0 mov [WindowHandle], rax test rax, rax jz creation_error stdcall InitDrawBuffer,GlobalDrawBuffer mov [GlobalRunning], 1 .loop: cmp [GlobalRunning], 0 je exit call Win32MessagePump jmp .loop registration_error: invoke MessageBoxA,0,WindowRegErrorMessage,WindowTitle,MB_ICONERROR+MB_OK jmp exit creation_error: invoke MessageBoxA,0,WindowCreateErrorMessage,WindowTitle,MB_ICONERROR+MB_OK ;jmp exit exit: invoke ExitProcess,[Message.wParam] ;--- proc InitDrawBuffer uses BitmapInfo, Pixels, Width, Height int3 ;TODO lea? whats a better way to do this... this is **** mov [BitmapInfo], rcx mov rax, [rcx+8] mov [Pixels], rax mov rax, [rcx+16] mov [Width], rax mov rax, [rcx+24] mov [Height], rax mov [bmiHeader.biSize], sizeof.BitmapInfo.bmiHeader ;mov [bmiHeader.biWidth], [Width] ;mov [bmiHeader.biHeight], [Height] mov [bmiHeader.biWidth], 500 mov [bmiHeader.biHeight], 900 mov [bmiHeader.biPlanes], 1 mov [bmiHeader.biBitCount], 32 mov [bmiHeader.biCompression], BI_RGB ret endp proc Win32DisplayBuffer invoke GetDC,WindowHandle ;invoke StretchDIBits,rax,0,0,Width,Height,0,0,Width,Height,Pixels,BitmapInfo,DIB_RGB_COLORS, SRCCOPY ret endp proc Win32MessagePump; uses WindowHandle .while_message: ;invoke PeekMessageA, Message, WindowHandle,0,0, PM_REMOVE ;TODO why does this freeze up? invoke GetMessage,Message,0,0,0 ;TODO replace with peekmessage cmp eax, 0 je .end cmp [Message.message], WM_QUIT mov [GlobalRunning], 0 je .end cmp [Message.message], WM_PAINT je .paint cmp [Message.message], WM_KEYDOWN je .keydown invoke TranslateMessage,Message invoke DispatchMessage,Message jmp .while_message .paint: push rax call Win32DisplayBuffer pop rax jmp .while_message .keydown: call Win32DisplayBuffer jmp .while_message .end: ret endp proc Win32CallbackProc ;proc WndProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam cmp edx, WM_DESTROY je .destroy .default: invoke DefWindowProcA,rcx,rdx,r8,r9 jmp .end .destroy: invoke PostQuitMessage,0 xor rax,rax .end: ret endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL',\ gdi, 'GDI32.DLL',\ import kernel,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess' import user,\ RegisterClassExA,'RegisterClassExA',\ CreateWindowExA,'CreateWindowExA',\ ShowWindow,'ShowWindow',\ UpdateWindow,'UpdateWindow',\ DefWindowProcA,'DefWindowProcA',\ GetMessage,'GetMessageA',\ TranslateMessage,'TranslateMessage',\ DispatchMessage,'DispatchMessageA',\ LoadCursor,'LoadCursorA',\ LoadIcon,'LoadIconA',\ GetClientRect,'GetClientRect',\ GetDC,'GetDC',\ ReleaseDC,'ReleaseDC',\ BeginPaint,'BeginPaint',\ EndPaint,'EndPaint',\ PostQuitMessage,'PostQuitMessage',\ MessageBoxA, 'MessageBoxA',\ PeekMessageA, 'PeekMessageA' import gdi,\ StretchDIBits, 'StretchDIBits' |
|||
04 Apr 2020, 02:07 |
|
revolution 04 Apr 2020, 02:23
The include is not a problem there.
But this will cause trouble: Code: gdi, 'GDI32.DLL',\ ; <--- extra trailing comma Code: proc InitDrawBuffer uses BitmapInfo, Pixels, Width, Height |
|||
04 Apr 2020, 02:23 |
|
B.Dubious 04 Apr 2020, 02:33
I've tried again and it's working now, I'm not sure what was wrong before... it could be that I was being an eejit somehow, it is 0330. I'm entirely sure I saved the buffers so perhaps I introduced some other error.
I think that extra trailing was something I added since the first try though, I was building cleanly then, and I did try to add another .lib to the list though I removed it again. I had a feeling I was misusing the uses keyword there, I'll look into these locals macros because all I really wanted was a local alias for the registers. Thanks for the guidance I should read the macros section of the docs thoroughly tomorrow. ps. are the code blocks markdown? |
|||
04 Apr 2020, 02:33 |
|
revolution 04 Apr 2020, 02:38
B.Dubious wrote: ps. are the code blocks markdown? Examine one of the previous messages with the quote button to see how it works. There is also the "Test" forum if you want to try stuff out. Last edited by revolution on 04 Apr 2020, 03:04; edited 1 time in total |
|||
04 Apr 2020, 02:38 |
|
B.Dubious 04 Apr 2020, 02:49
Cool, I'll try to use the proper markup in future.
For now I'll try and make a little more progress with this and get to bed. Thanks for all your help |
|||
04 Apr 2020, 02:49 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.