flat assembler
Message board for the users of flat assembler.
Index
> Windows > Displaying a pixel buffer |
Author |
|
Mota 31 Dec 2004, 13:58
Please People, I really need your help. There must e a way to make it work!
If I uncomment 'invoke StretchDIBits, ...' it doesnt crash. Whats the problem? Please help. |
|||
31 Dec 2004, 13:58 |
|
JohnFound 31 Dec 2004, 14:12
Mota wrote: Please People, I really need your help. There must e a way to make it work! Hm, I simply can't understand your problem... doesn't work is not an explanation and definately noone will try to guess what you have to explain... Also, your code is uncompilable, because it depends on some other files and you are using "../../../some.asm" - beleave me, my directory structure is not as yours... Simply prepare your homework and you will get all help you can carry. Regards and happy new year. |
|||
31 Dec 2004, 14:12 |
|
Mota 31 Dec 2004, 17:36
'..\..\..\include\' is my include path. I dunno how to use environment variables, so maybe you people could help me there too
'..\..\..\include\own\main.asm' should really be called main.inc. It contains a single definition: array equ times im trying to display a pixel buffer, called buffer, onto my window using StretchDIBits. Whenever the program reaches StretchDIBits, it crashes. There could be many reasons to this, but ive tried all I can think of and it still crashes. |
|||
31 Dec 2004, 17:36 |
|
JohnFound 31 Dec 2004, 18:17
Mota wrote: I dunno how to use environment variables, so maybe you people could help me there too You could use the search function of this forum. Try this: http://board.flatassembler.net/topic.php?t=805 OK, I will look at your sources... Happy new year. |
|||
31 Dec 2004, 18:17 |
|
Mota 01 Jan 2005, 17:24
Thanks, happy new year everyone
|
|||
01 Jan 2005, 17:24 |
|
JohnFound 03 Jan 2005, 00:30
Hi, Mota.
I fixed your sources. There was several problems. Also, I rewrote some fragments in more standard and safe way (also to use %fasminc% environment variable). Check sources - there are short comments for you. And hey, don't use so big horizontal indents. Make your sources readable with vertical indents instead (only IMHO. ) Code: ; Generally speaking this way of allocating bitmaps is not very good, ; better use HeapAlloc with reallocation on WM_SIZE ; Also, using only global labels for bigger programs may lead to ; problems with name space exhoust - you simply can't invent so many ; different names. Use local labels (with "." as first char) that will ; save you a lot of troubles when the project grows. ; format PE GUI 4.0 entry start include '%fasminc%\win32a.inc' SCRWIDTH equ 680 SCRHEIGHT equ 480 section '.code' code readable executable start: ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke GetModuleHandle,NULL mov [wHInstance],eax mov [wCls.hInstance],0;eax mov [wCls.style],CS_HREDRAW or CS_VREDRAW or CS_OWNDC mov [wCls.lpfnWndProc],window_procedure mov [wCls.lpszClassName],wClsName mov [wCls.hbrBackground],COLOR_WINDOW+1 invoke LoadIcon,NULL,IDI_APPLICATION mov [wCls.hIcon],eax invoke LoadCursor,NULL,IDC_ARROW mov [wCls.hCursor],eax mov [bmi.biSize], sizeof.BITMAPINFOHEADER mov [bmi.biWidth],SCRWIDTH mov [bmi.biHeight],-SCRHEIGHT mov [bmi.biPlanes],1 mov [bmi.biBitCount], 32 mov [bmi.biCompression], BI_RGB ; ignore these mov [bmi.biSizeImage], 0 mov [bmi.biXPelsPerMeter],0 mov [bmi.biYPelsPerMeter],0 mov [bmi.biClrUsed],0 mov [bmi.biClrImportant],0 mov [rect.left],0 mov [rect.top],0 mov [rect.right],SCRWIDTH mov [rect.bottom],SCRHEIGHT invoke AdjustWindowRect, rect, WS_POPUP or WS_SYSMENU or WS_CAPTION, 0 invoke RegisterClass,wCls ; +--------------------------+ ; | creating the main window | ; +--------------------------+ mov ecx, [rect.bottom] mov eax, [rect.right] sub ecx, [rect.top] sub eax, [rect.left] invoke CreateWindowEx,\ 0,\ wClsName,\ wTitle,\ WS_OVERLAPPEDWINDOW xor WS_THICKFRAME xor WS_MAXIMIZEBOX,\ 0,\ 0,\ eax,\ ecx,\ NULL,\ NULL,\ [wHInstance],\ NULL mov [wHMain],eax invoke ShowWindow,[wHMain],SW_SHOW ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ window_message_loop_start: invoke GetMessage,wMsg,NULL,0,0 or eax,eax je window_message_loop_end invoke TranslateMessage, wMsg invoke DispatchMessage, wMsg jmp window_message_loop_start window_message_loop_end: invoke ExitProcess, 0 ; +----------------------+ ; | the window procedure | ; +----------------------+ proc window_procedure, hWnd, uMsg, wParam, lParam push ebx esi edi ;eventhough the API would preserved, but play safe :p cmp [uMsg],WM_DESTROY je wmDESTROY cmp [uMsg],WM_PAINT je wmPAINT cmp [uMsg], WM_ERASEBKGND je wmERASE cmp [uMsg],WM_KEYDOWN je wmKEY wmDEFAULT: invoke DefWindowProc,[hWnd],[uMsg],[wParam],[lParam] jmp wmFINISH wmPAINT: ; Never get DC for long. Use BeginPaint|EndPaint in WM_PAINT handlers. invoke BeginPaint, [hWnd], paintstruct invoke StretchDIBits, [paintstruct.hdc], 0, 0, SCRWIDTH, SCRHEIGHT, 0, 0, SCRWIDTH, SCRHEIGHT, buffer, bmi, 0, SRCCOPY invoke EndPaint, [hWnd], paintstruct jmp wmBYE ; Handle WM_ERASE and return TRUE - this will prevent flickering of the window on repaint. wmERASE: xor eax, eax inc eax jmp wmFINISH wmKEY: and [wParam],0FFh cmp [wParam],27 jne wmBYE wmDESTROY: invoke PostQuitMessage,0 wmBYE: xor eax, eax wmFINISH: pop edi esi ebx return endp section '.data' data readable writeable ; Place your data after the code - especially for so big arrays. ; Place uninitialized data at the end of the section. wTitle db 'GOD',0 ;name of our window wClsName db 'GODCLASS',0 ;name of our window class wHMain dd ? wHInstance dd ? wMsg MSG wCls WNDCLASS rect RECT paintstruct PAINTSTRUCT bmi BITMAPINFOHEADER buffer rd SCRWIDTH * SCRHEIGHT ; black DIB section '.idata' import data readable writeable ; Import everything - FASM will select only API's you use in the program. library kernel32, 'KERNEL32.DLL',\ user32, 'USER32.DLL', \ gdi32, 'gdi32.dll' include "%fasminc%\apia\kernel32.inc" include "%fasminc%\apia\user32.inc" include "%fasminc%\apia\gdi32.inc" Regards. |
|||
03 Jan 2005, 00:30 |
|
Mota 03 Jan 2005, 01:38
thanks!
I couldnt have done anything better! the beginpaint and endpaint part is what bugs me, i need to spend the leas amount of time to paint a frame, and I want to be able to paint outside of WM_PAINT messages. Anyway, thanks a bunch! |
|||
03 Jan 2005, 01:38 |
|
vbVeryBeginner 03 Jan 2005, 04:53
Quote:
this sounds familiar :-p lol Code: mov [wCls.hInstance],0;eax should be mov [wCls.hInstance],eax |
|||
03 Jan 2005, 04:53 |
|
Mota 04 Jan 2005, 17:50
Yes, it must sound familiar to you
Those tutorials are really useful, you know the hInstance thing is because I saw it on a c++ implementation and was testing it. Thanks JohnFound, vbVeryBegginer, for the help. I will forever be in your debt (sounds familiar too ) |
|||
04 Jan 2005, 17:50 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.