Advertisement
deced

Untitled

Jan 9th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.30 KB | None | 0 0
  1.  
  2. ; DirectDraw programming example
  3.  
  4. format PE GUI 4.0
  5. entry start
  6.  
  7. include 'win32a.inc'
  8. ф
  9. include 'ddraw.inc'
  10.  
  11. section '.text' code readable executable
  12.  
  13. start:
  14.  
  15. and [DDraw],0
  16. and [DDSPrimary],0
  17. and [DDSBack],0
  18. and [DDPalette],0
  19. and [DDSPicture],0
  20.  
  21. invoke GetModuleHandleA,NULL
  22. mov [hinstance],eax
  23.  
  24. invoke LoadIconA,NULL,IDI_APPLICATION
  25. mov [wc.hIcon],eax
  26.  
  27. invoke LoadCursorA,NULL,IDC_ARROW
  28. mov [wc.hCursor],eax
  29.  
  30. mov [wc.style],0
  31. mov [wc.lpfnWndProc],WindowProc
  32. mov [wc.cbClsExtra],0
  33. mov [wc.cbWndExtra],0
  34. mov eax,[hinstance]
  35. mov [wc.hInstance],eax
  36. mov [wc.hbrBackground],0
  37. mov dword [wc.lpszMenuName],NULL
  38. mov dword [wc.lpszClassName],_class
  39. invoke RegisterClassA,wc
  40. test eax,eax
  41. jz startup_error
  42.  
  43. invoke CreateWindowExA,\
  44. 0,_class,_title,WS_POPUP+WS_VISIBLE,0,0,0,0,NULL,NULL,[hinstance],NULL
  45. test eax,eax
  46. jz startup_error
  47. mov [hwnd],eax
  48.  
  49. invoke DirectDrawCreate,NULL,DDraw,NULL
  50. or eax,eax
  51. jnz ddraw_error
  52.  
  53. cominvk DDraw,SetCooperativeLevel,\
  54. [hwnd],DDSCL_EXCLUSIVE+DDSCL_FULLSCREEN
  55. or eax,eax
  56. jnz ddraw_error
  57.  
  58. cominvk DDraw,SetDisplayMode,\
  59. 640,480,8
  60. or eax,eax
  61. jnz ddraw_error
  62.  
  63. mov [ddsd.dwSize],sizeof.DDSURFACEDESC
  64. mov [ddsd.dwFlags],DDSD_CAPS+DDSD_BACKBUFFERCOUNT
  65. mov [ddsd.ddsCaps.dwCaps],DDSCAPS_PRIMARYSURFACE+DDSCAPS_FLIP+DDSCAPS_COMPLEX
  66. mov [ddsd.dwBackBufferCount],1
  67. cominvk DDraw,CreateSurface,\
  68. ddsd,DDSPrimary,NULL
  69. or eax,eax
  70. jnz ddraw_error
  71.  
  72. mov [ddscaps.dwCaps],DDSCAPS_BACKBUFFER
  73. cominvk DDSPrimary,GetAttachedSurface,\
  74. ddscaps,DDSBack
  75. or eax,eax
  76. jnz ddraw_error
  77.  
  78. mov esi,picture
  79. call load_picture
  80. jc open_error
  81.  
  82. mov esi,picture
  83. call load_palette
  84. jc open_error
  85.  
  86. invoke GetTickCount
  87. mov [last_tick],eax
  88.  
  89. jmp paint
  90.  
  91. main_loop:
  92.  
  93. invoke PeekMessageA,msg,NULL,0,0,PM_NOREMOVE
  94. or eax,eax
  95. jz no_message
  96. invoke GetMessageA,msg,NULL,0,0
  97. or eax,eax
  98. jz end_loop
  99. invoke TranslateMessage,msg
  100. invoke DispatchMessageA,msg
  101.  
  102. jmp main_loop
  103.  
  104. no_message:
  105. cmp [active],0
  106. je sleep
  107.  
  108. cominvk DDSPrimary,IsLost
  109. or eax,eax
  110. jz paint
  111. cmp eax,DDERR_SURFACELOST
  112. jne end_loop
  113.  
  114. cominvk DDSPrimary,Restore
  115.  
  116. paint:
  117.  
  118. mov [rect.top],0
  119. mov [rect.bottom],480
  120. mov [rect.left],0
  121. mov [rect.right],640
  122.  
  123. cominvk DDSBack,BltFast,\
  124. 0,0,[DDSPicture],rect,DDBLTFAST_SRCCOLORKEY
  125. or eax,eax
  126. jnz paint_done
  127.  
  128. movzx eax,[frame]
  129. xor edx,edx
  130. mov ebx,10
  131. div ebx
  132.  
  133. sal eax,6
  134. add eax,480
  135. mov [rect.top],eax
  136. add eax,64
  137. mov [rect.bottom],eax
  138. sal edx,6
  139. mov [rect.left],edx
  140. add edx,64
  141. mov [rect.right],edx
  142.  
  143. cominvk DDSBack,BltFast,\
  144. [x],[y],[DDSPicture],rect,DDBLTFAST_SRCCOLORKEY
  145.  
  146. cominvk DDSPrimary,SetPalette,[DDPalette]
  147.  
  148. cominvk DDSPrimary,Flip,0,0
  149.  
  150. paint_done:
  151.  
  152. invoke GetTickCount
  153. mov ebx,eax
  154. sub ebx,[last_tick]
  155. cmp ebx,20
  156. jb main_loop
  157. add [last_tick],20
  158.  
  159. inc [frame]
  160. cmp [frame],60
  161. jb main_loop
  162. mov [frame],0
  163. jmp main_loop
  164.  
  165. sleep:
  166. invoke WaitMessage
  167. jmp main_loop
  168.  
  169. ddraw_error:
  170. mov eax,_ddraw_error
  171. jmp error
  172. open_error:
  173. mov eax,_open_error
  174. error:
  175. invoke MessageBoxA,[hwnd],eax,_error,MB_OK+MB_ICONERROR
  176. invoke DestroyWindow,[hwnd]
  177. invoke PostQuitMessage,1
  178. jmp main_loop
  179. startup_error:
  180. invoke MessageBoxA,[hwnd],_startup_error,_error,MB_OK+MB_ICONERROR
  181. end_loop:
  182.  
  183. cmp [DDSPicture],0
  184. je picture_released
  185. cominvk DDSPicture,Release
  186. picture_released:
  187. cmp [DDPalette],0
  188. je palette_released
  189. cominvk DDPalette,Release
  190. palette_released:
  191. cmp [DDSBack],0
  192. je back_surface_released
  193. cominvk DDSPrimary,DeleteAttachedSurface,0,DDSBack
  194. back_surface_released:
  195. cmp [DDSPrimary],0
  196. je primary_surface_released
  197. cominvk DDSPrimary,Release
  198. primary_surface_released:
  199. cmp [DDraw],0
  200. je ddraw_released
  201. cominvk DDraw,Release
  202. ddraw_released:
  203.  
  204. invoke ExitProcess,[msg.wParam]
  205.  
  206. include 'gif87a.inc'
  207.  
  208. proc WindowProc hwnd,wmsg,wparam,lparam
  209. push ebx esi edi
  210. mov eax,[wmsg]
  211. cmp eax,WM_CREATE
  212. je .wmcreate
  213. cmp eax,WM_DESTROY
  214. je .wmdestroy
  215. cmp eax,WM_ACTIVATE
  216. je .wmactivate
  217. cmp eax,WM_SETCURSOR
  218. je .wmsetcursor
  219. cmp eax,WM_MOUSEMOVE
  220. je .wmmousemove
  221. cmp eax,WM_KEYDOWN
  222. je .wmkeydown
  223. .defwindowproc:
  224. invoke DefWindowProcA,[hwnd],[wmsg],[wparam],[lparam]
  225. jmp .finish
  226. .wmcreate:
  227. xor eax,eax
  228. jmp .finish
  229. .wmkeydown:
  230. cmp [wparam],VK_ESCAPE
  231. jne .finish
  232. .wmdestroy:
  233. cominvk DDraw,RestoreDisplayMode
  234. invoke PostQuitMessage,0
  235. xor eax,eax
  236. jmp .finish
  237. .wmactivate:
  238. mov eax,[wparam]
  239. mov [active],al
  240. jmp .finish
  241. .wmsetcursor:
  242. invoke SetCursor,0
  243. xor eax,eax
  244. jmp .finish
  245. .wmmousemove:
  246. movsx eax,word [lparam]
  247. mov [x],eax
  248. movsx eax,word [lparam+2]
  249. mov [y],eax
  250. .finish:
  251. pop edi esi ebx
  252. ret
  253. endp
  254.  
  255. section '.data' data readable writeable
  256.  
  257. _title db 'flat assembler DirectDraw application',0
  258. _class db 'FDDRAW32',0
  259.  
  260. _error db 'Error',0
  261. _startup_error db 'Startup failed.',0
  262. _ddraw_error db 'Direct Draw initialization failed.',0
  263. _open_error db 'Failed opening data file.',0
  264.  
  265. picture db 'DDRAW.GIF',0
  266.  
  267. section '.bss' readable writeable
  268.  
  269. hinstance dd ?
  270. hwnd dd ?
  271. wc WNDCLASS
  272. msg MSG
  273.  
  274. ddsd DDSURFACEDESC
  275. ddscaps DDSCAPS
  276.  
  277. DDraw DirectDraw
  278. DDSPrimary DirectDrawSurface
  279. DDSBack DirectDrawSurface
  280.  
  281. DDSPicture DirectDrawSurface
  282. DDPalette DirectDrawPalette
  283.  
  284. bytes_count dd ?
  285. last_tick dd ?
  286. frame db ?
  287. active db ?
  288. LZW_bits db ?
  289. LZW_table rd (0F00h-2)*2
  290. buffer rb 40000h
  291. rect RECT
  292. x dd ?
  293. y dd ?
  294.  
  295. section '.idata' import data readable
  296.  
  297. library kernel,'KERNEL32.DLL',\
  298. user,'USER32.DLL',\
  299. ddraw,'DDRAW.DLL'
  300.  
  301. import kernel,\
  302. GetModuleHandleA,'GetModuleHandleA',\
  303. CreateFileA,'CreateFileA',\
  304. ReadFile,'ReadFile',\
  305. CloseHandle,'CloseHandle',\
  306. GetTickCount,'GetTickCount',\
  307. ExitProcess,'ExitProcess'
  308.  
  309. import user,\
  310. RegisterClassA,'RegisterClassA',\
  311. CreateWindowExA,'CreateWindowExA',\
  312. DestroyWindow,'DestroyWindow',\
  313. DefWindowProcA,'DefWindowProcA',\
  314. GetMessageA,'GetMessageA',\
  315. PeekMessageA,'PeekMessageA',\
  316. TranslateMessage,'TranslateMessage',\
  317. DispatchMessageA,'DispatchMessageA',\
  318. LoadCursorA,'LoadCursorA',\
  319. LoadIconA,'LoadIconA',\
  320. SetCursor,'SetCursor',\
  321. MessageBoxA,'MessageBoxA',\
  322. PostQuitMessage,'PostQuitMessage',\
  323. WaitMessage,'WaitMessage'
  324.  
  325. import ddraw,\
  326. DirectDrawCreate,'DirectDrawCreate'
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement