+ All Categories
Home > Documents > Td Win32asm 170.Asm

Td Win32asm 170.Asm

Date post: 17-Feb-2018
Category:
Upload: z4rm4r
View: 227 times
Download: 0 times
Share this document with a friend

of 40

Transcript
  • 7/23/2019 Td Win32asm 170.Asm

    1/40

  • 7/23/2019 Td Win32asm 170.Asm

    2/40

    td_win32asm_170.asmoption casemap:none ; case sensitive !

    ;==============================================================================; Include all files where API functions resist you want use, set correct path;------------------------------------------------------------------------------include windows.incincludelib kernel32.lib

    includelib user32.libincludelib comdlg32.libincludelib gdi32.libincludelib winmm.lib

    ;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetLastError PROTOGetModuleHandleA PROTO :DWORD

    GetSystemMetrics PROTO :DWORDEnumDisplaySettingsA PROTO :DWORD,:DWORD,:DWORDChangeDisplaySettingsA PROTO :DWORD,:DWORDGetCurrentThread PROTOSetThreadPriority PROTO :DWORD,:DWORDLoadIconA PROTO :DWORD,:DWORDCreateSolidBrush PROTO :DWORDLoadCursorA PROTO :DWORD,:DWORDRegisterClassExA PROTO :DWORDCreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

    ShowWindow PROTO :DWORD,:DWORDUpdateWindow PROTO :DWORDGetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDTranslateMessage PROTO :DWORDDispatchMessageA PROTO :DWORDPostQuitMessage PROTO :DWORDDestroyWindow PROTO :DWORDDefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORDExitProcess PROTO :DWORDMessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD

    LoadBitmapA PROTO :DWORD,:DWORDGetMenu PROTO :DWORDCheckMenuItem PROTO :DWORD,:DWORD,:DWORDEnableMenuItem PROTO :DWORD,:DWORD,:DWORDInvalidateRect PROTO :DWORD,:DWORD,:DWORDFillRect PROTO :DWORD,:DWORD,:DWORDGetDeviceCaps PROTO :DWORD,:DWORDGetDC PROTO :DWORDGetObjectA PROTO :DWORD,:DWORD,:DWORDReleaseDC PROTO :DWORD,:DWORDGetDIBits PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

    CreateDIBSection PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORDCreateCompatibleDC PROTO :DWORDCreateCompatibleBitmap PROTO :DWORD,:DWORD,:DWORDSelectObject PROTO :DWORD,:DWORD

    Page 2

  • 7/23/2019 Td Win32asm 170.Asm

    3/40

  • 7/23/2019 Td Win32asm 170.Asm

    4/40

  • 7/23/2019 Td Win32asm 170.Asm

    5/40

  • 7/23/2019 Td Win32asm 170.Asm

    6/40

    td_win32asm_170.asm; - DEVMODE Structure ( API=EnumDisplaySettings / ChangeDisplaySettings ) -dmDeviceName db 32 dup (?)dmSpecVersion dw ?dmDriverVersion dw ?dmSize dw ?dmDriverExtra dw ?dmFields dd ?

    dmOrientation dw ?dmPaperSize dw ?dmPaperLength dw ?dmPaperWidth dw ?dmScale dw ?dmCopies dw ?dmDefaultSource dw ?dmPrintQuality dw ?dmColor dw ?dmDuplex dw ?

    dmYResolution dw ?dmTTOption dw ?dmCollate dw ?dmFormName db 32 dup (?)dmLogPixels dw ?dmBitsPerPel dd ?dmPelsWidth dd ?dmPelsHeight dd ?dmDisplayFlags dd ?dmDisplayFrequency dd ?dmICMMethod dd ? ;Windows 95 only

    dmICMIntent dd ? ;Windows 95 onlydmMediaType dd ? ;Windows 95 onlydmDitherType dd ? ;Windows 95 onlydmReserved1 dd ? ;Windows 95 onlydmReserved2 dd ? ;Windows 95 only

    align 4; - WndClassEx Structure ( API=RegisterClassExA ) -cbSize dd ? ;size in bytes of this structurestyle dd ? ;window style

    lpfnWndProc dd ? ;address of user proc functioncbclsExtra dd ? ;extra bytes to allocate set to 0cbWndExtra dd ? ;extra bytes class directive, rc filehInstance dd ? ;program handle(API=GetModuleHandleA)hIcon dd ? ;handle of icon (API=LoadIconA)hcursor dd ? ;handle of cursor (API=LoadCursor)hbrBackground dd ? ;background color, 0=transparentlpszMenuName dd ? ;name of menu class in resource filelpszClassName dd ? ;name of windows this window classhIconSm dd ? ;iconhandle 0=search in resource file

    align 4; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structurehWnd dd ? ;handle of window who receives messagemessage dd ? ;the message number

    Page 6

  • 7/23/2019 Td Win32asm 170.Asm

    7/40

  • 7/23/2019 Td Win32asm 170.Asm

    8/40

  • 7/23/2019 Td Win32asm 170.Asm

    9/40

  • 7/23/2019 Td Win32asm 170.Asm

    10/40

  • 7/23/2019 Td Win32asm 170.Asm

    11/40

  • 7/23/2019 Td Win32asm 170.Asm

    12/40

  • 7/23/2019 Td Win32asm 170.Asm

    13/40

    td_win32asm_170.asmpush hdcDest ;hdcDest, handle destination devicecall BitBlt ;- API Function -;------------------------------------------------------------------------------; API "EndPaint" marks the end of painting in the given window.; This function is required for each call to the BeginPaint function, but only; after painting is complete.;------------------------------------------------------------------------------

    push OFFSET hdc ;lpPaint, pointer PAINTSTRUCTpush WP1_hWnd ;hwnd, handle of the windowcall EndPaint ;- API Function -mov WM_PAINT_proceed,1h ;set flag, WM_PAINT is proceed !jmp WP1_return

    ;==============================================================================; WM_COMMAND (value=111h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_111h:cmp eax,111h ;check if WM_COMMAND message recievedjne WP1_uMsg_112h ;if not goto labelmov eax,WP1_wParam ;extra info about the message in axWP1_uMsg_wParam_10h:cmp ax,10h ;"Load Bitmap" clicked ?jne WP1_uMsg_wParam_12h ;call My_EffectCodeAll_Off ;- Subroutine -call My_LoadBMP ;- Subroutine -call My_RestoreScreen ;- Subroutine -jmp WP1_return

    WP1_uMsg_wParam_12h:cmp ax,12h ;"Save Bitmap" clicked ?jne WP1_uMsg_wParam_20h ;call My_EffectCodeAll_Off ;- Subroutine -call My_SaveBMP ;- Subroutine -call My_RestoreScreen ;- Subroutine -jmp WP1_return

    WP1_uMsg_wParam_20h:cmp ax,20h ;"Effect off" clicked ?jne WP1_uMsg_wParam_21h ;call My_EffectCodeAll_Off ;- Subroutine -call My_RestoreScreen ;- Subroutine -jmp WP1_return

    WP1_uMsg_wParam_21h:cmp ax,21h ;"Spotlight 1" clicked ?jne WP1_uMsg_wParam_22h ;call My_EffectCode001_On ;- Subroutine -jmp WP1_return

    WP1_uMsg_wParam_22h:cmp ax,22h ;"Spotlight 2" clicked ?jne WP1_uMsg_wParam_A0h ;call My_EffectCode002_On ;- Subroutine -

    Page 13

  • 7/23/2019 Td Win32asm 170.Asm

    14/40

    td_win32asm_170.asmjmp WP1_return

    WP1_uMsg_wParam_A0h:cmp ax,0A0h ;"AutoMode" clicked ?jne WP1_uMsg_wParam_A1h ;call My_AutoMode ;- Subroutine -jmp WP1_return

    WP1_uMsg_wParam_A1h:cmp ax,0A1h ;"Keyboard" clicked ?jne WP1_return ;call My_Keyboard ;- Subroutine -jmp WP1_return

    ;==============================================================================; WM_SYSCOMMAND (value=112h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_112h:cmp eax,112h ;check if WM_COMMAND message recievedjne WP1_return ;if not goto labelmov eax,WP1_wParam ;extra info about the messagecmp eax,0F060h ;SC_CLOSE=0F060h received ?jne WP1_return ;call My_CleanSystem ;- SubRoutine -jmp WP1_return

    ;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing

    ; for any window messages that an application does not process.; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------WP1_return:popad ;pop all register from stackpush WP1_lParam ;extra info about the messagepush WP1_wParam ;extra info about the messagepush WP1_uMsg ;the message numberpush WP1_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -mov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack;##############################################################################

    ;##############################################################################; HIGH RESOLUTION TIMER procedure (Mmedia.hlp) !;------------------------------------------------------------------------------TP1:pushad ;save all register

    cmp WM_PAINT_proceed,1h ;check if last WM_PAINT msg. is proceedjne TP1_return ;if not 1h nothing to do, TIME CRITICAL

    Page 14

  • 7/23/2019 Td Win32asm 170.Asm

    15/40

    td_win32asm_170.asmcmp AutoMode,1h ;check AutoMode flagje Table_Spotlight ;skip AutoMode;------------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the; function is called ...;------------------------------------------------------------------------------push 26h ;vKey, virtual-key code, VK_UP=26h

    call GetAsyncKeyState ;- API Function -shr eax,1Fhcmp eax,1hjne LeftArrowadd eax,71jmp Go

    LeftArrow:;------------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the; function is called ...;------------------------------------------------------------------------------push 25h ;vKey, virtual-key code, VK_LEFT=25hcall GetAsyncKeyState ;- API Function -shr eax,1Fhcmp eax,1hjne RightArrowadd eax,74jmp Go

    RightArrow:

    ;------------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the; function is called ...;------------------------------------------------------------------------------push 27h ;vKey, virtual-key code, VK_RIGHT=27hcall GetAsyncKeyState ;- API Function -shr eax,1Fhcmp eax,1hjne DownArrowadd eax,76jmp Go

    DownArrow:;------------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the; function is called ...;------------------------------------------------------------------------------push 28h ;vKey, virtual-key code, VK_DOWN=28hcall GetAsyncKeyState ;- API Function -shr eax,1Fhcmp eax,1h

    jne TP1_returnadd eax,79jmp Go

    Page 15

  • 7/23/2019 Td Win32asm 170.Asm

    16/40

    td_win32asm_170.asmTable_Spotlight:mov eax,Index_spotlight ;get value from tablemov ebx,OFFSET Table_spotlight ;add ebx,eax ;mov al,[ebx] ;inc Index_spotlight ;cmp Index_spotlight,180 ;

    jbe Go ;mov Index_spotlight,0h ;

    Go:mov ecx,Yspeed ;vertical speedmov edx,Xspeed ;horizontal speedmov esi,Xpos_max ;max. window widthmov edi,Ypos_max ;max. window height

    Up:cmp al,72 ;up arrow key = 72jne Leftcmp OffYpos_work,0hja SubY_workcmp OffYpos_light,edijae TP1_returnadd OffYpos_light,ecxsub edi,OffYpos_lightmov OffYpos_max,edijmp EffectSubY_work:

    sub OffYpos_work,ecxsub edi,OffYpos_workmov OffYpos_max,edijmp Effect

    Left:cmp al,75 ;left arrow key = 75jne Rightcmp OffXpos_work,0hja SubX_workcmp OffXpos_light,esijae TP1_returnadd OffXpos_light,edxsub esi,OffXpos_lightmov OffXpos_max,esijmp EffectSubX_work:sub OffXpos_work,edxsub esi,OffXpos_workmov OffXpos_max,esijmp Effect

    Right:cmp al,77 ;right arrow key = 77jne Down

    Page 16

    d i 32 170

  • 7/23/2019 Td Win32asm 170.Asm

    17/40

    td_win32asm_170.asmcmp OffXpos_light,0hje AddX_worksub OffXpos_light,edxsub esi,OffXpos_lightmov OffXpos_max,esijmp EffectAddX_work:

    cmp OffXpos_work,esijae TP1_returnadd OffXpos_work,edxsub esi,OffXpos_workmov OffXpos_max,esijmp Effect

    Down:cmp al,80 ;down arrow key = 80jne TP1_returncmp OffYpos_light,0h

    je AddY_worksub OffYpos_light,ecxsub edi,OffYpos_lightmov OffYpos_max,edijmp EffectAddY_work:cmp OffYpos_work,edijae TP1_returnadd OffYpos_work,ecxsub edi,OffYpos_work

    mov OffYpos_max,edi

    Effect:call My_EffectCode ;- Subroutine -mov WM_PAINT_proceed,0h ;reset flag

    TP1_return:popad ;pop all register back from stackret 14h ;return and clear stack (14h !!!);##############################################################################

    ;******************************************************************************; My own (sub)routine(s) for a compacter code resist here ...;------------------------------------------------------------------------------My_CleanSystem:call My_EffectCodeAll_Off ;- Subroutine -;------------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or; palette, freeing all system resources associated with the object.;------------------------------------------------------------------------------push handleBMP ;hObject, handle compatible graphic object

    call DeleteObject ;- API Function -;------------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or; palette, freeing all system resources associated with the object.

    Page 17

  • 7/23/2019 Td Win32asm 170.Asm

    18/40

    td win32asm 170 asm

  • 7/23/2019 Td Win32asm 170.Asm

    19/40

    td_win32asm_170.asmpush OffXpos_work ;nXDest, x=dest. rect. up-left cornerpush handleCDC_work ;hdcDest, handle destination devicecall BitBlt ;- API Function -;------------------------------------------------------------------------------; This is my routine to manipulate the bitmap. It must (!) be short and fast.;------------------------------------------------------------------------------mov ecx,sizeBMP ;max. size of bitmap

    mov esi,pointerBMP_back ;pointer background bitmap memory areamov edi,pointerBMP_work ;pointer working bitmap memory area

    cmp TP1_Mode,1h ;jne EffectCode_002 ;My_EffectCode_001:mov al,[edi] ;calculating the spotlight effect 001cmp al,0hjne YesEffectCode_001mov al,[esi]jmp NoEffectCode_001

    YesEffectCode_001:mov bl,0FFhmov ah,[esi]sub bl,ahcmp bl,aljae OkEffectCode_001mov al,blOkEffectCode_001:add al,ahNoEffectCode_001:

    mov [edi],alinc esiinc edidec ecxjne My_EffectCode_001jmp My_EffectCode_Done

    EffectCode_002:cmp TP1_Mode,2h ;jne My_EffectCode_return ;My_EffectCode_002:

    mov eax,[edi] ;calculating the spotlight effect 002and eax,0FFFFFF00hcmp eax,0hjne Test01_EffectCode_002mov al,[esi]mov [edi],almov al,[esi+1]mov [edi+1],almov al,[esi+2]mov [edi+2],al

    add esi,3add edi,3sub ecx,3jne My_EffectCode_002

    Page 19

    td win32asm 170 asm

  • 7/23/2019 Td Win32asm 170.Asm

    20/40

    td_win32asm_170.asmjmp My_EffectCode_Done

    Test01_EffectCode_002:mov eax,[esi]and eax,0FFFFFF00hcmp eax,0hjne Test02_EffectCode_002

    mov [edi],almov [edi+1],almov [edi+2],aladd esi,3add edi,3sub ecx,3jne My_EffectCode_002jmp My_EffectCode_Done

    Test02_EffectCode_002:mov edx,3

    LoopEffectCode_002:mov al,[edi]mov bl,0FFhmov ah,[esi]sub bl,ahcmp bl,aljae OkEffectCode_002mov al,blOkEffectCode_002:add al,ah

    mov [edi],alinc esiinc edidec ecxje My_EffectCode_Donedec edxjne LoopEffectCode_002jmp My_EffectCode_002

    My_EffectCode_Done:;------------------------------------------------------------------------------

    ; API "InvalidateRect" adds a rectangle to specified window's update region.; This function performs a WM_PAINT message.;------------------------------------------------------------------------------push 0h ;bErase, erase-background flagpush 0h ;lpRect, rect structure, 0h=client areapush handleWindow ;hWnd, handle window update regioncall InvalidateRect ;- API Function -My_EffectCode_return:ret

    My_WM_CREATE:mov eax,WP1_hWnd ;store main window handlemov handleWindow,eax ;;------------------------------------------------------------------------------

    Page 20

  • 7/23/2019 Td Win32asm 170.Asm

    21/40

  • 7/23/2019 Td Win32asm 170.Asm

    22/40

  • 7/23/2019 Td Win32asm 170.Asm

    23/40

  • 7/23/2019 Td Win32asm 170.Asm

    24/40

  • 7/23/2019 Td Win32asm 170.Asm

    25/40

  • 7/23/2019 Td Win32asm 170.Asm

    26/40

  • 7/23/2019 Td Win32asm 170.Asm

    27/40

  • 7/23/2019 Td Win32asm 170.Asm

    28/40

  • 7/23/2019 Td Win32asm 170.Asm

    29/40

  • 7/23/2019 Td Win32asm 170.Asm

    30/40

  • 7/23/2019 Td Win32asm 170.Asm

    31/40

    td_win32asm_170.asmmov eax,Xpos_max ;check if our window < bitmap widthcmp eax biWidth temp

  • 7/23/2019 Td Win32asm 170.Asm

    32/40

    cmp eax,biWidth_tempjb ScaleBMPsub eax,biWidth_tempshr eax,1hmov XposOrg_temp,eax;------------------------------------------------------------------------------mov eax,Ypos_max ;check if our window < bitmap heightcmp eax,biHeight_tempjb ScaleBMPsub eax,biHeight_tempshr eax,1hmov YposOrg_temp,eaxmov eax,biHeight_tempmov Height_temp,eaxmov eax,biWidth_tempmov Width_temp,eaxjmp CreateBMP_temp

    ;------------------------------------------------------------------------------ScaleBMP:mov eax,Ypos_max ;scale bitmap to our window metricsmov Height_temp,eaxinc Height_tempScaleBMP_loop:dec Height_temp ;set new calculated heightffree ST(7) ;free ST(7), must be empty for loadfild biWidth_temp ;load bitmap width, integerfidiv biHeight_temp ;div, biWidth/biHeight, scale factor !fimul Height_temp ;mul, scale factor*Height_tempfistp Width_temp ;store new calculated widthmov eax,Xpos_maxcmp Width_temp,eax ;compareja ScaleBMP_loop ;loop;------------------------------------------------------------------------------mov eax,Xpos_max ;center scaled bitmap into window, Xpossub eax,Width_tempshr eax,1hmov XposOrg_temp,eaxmov eax,Ypos_max ;center scaled bitmap into window, Ypos

    sub eax,Height_tempshr eax,1hmov YposOrg_temp,eax

    CreateBMP_temp:;------------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left; and top borders, but excludes the right and bottom borders of the rectangle.;------------------------------------------------------------------------------push hbrBackground ;hbr, handle of brushpush OFFSET Xpos_org ;lprc, address of rectangle structurepush handleCDC_back ;hDC, handle of device contextcall FillRect ;- API Function -;------------------------------------------------------------------------------

    Page 32

  • 7/23/2019 Td Win32asm 170.Asm

    33/40

  • 7/23/2019 Td Win32asm 170.Asm

    34/40

  • 7/23/2019 Td Win32asm 170.Asm

    35/40

  • 7/23/2019 Td Win32asm 170.Asm

    36/40

  • 7/23/2019 Td Win32asm 170.Asm

    37/40

  • 7/23/2019 Td Win32asm 170.Asm

    38/40

    td_win32asm_170.asmret

    My HexDDtoStringDec: ;don't forget to save register (pushad/popad)

  • 7/23/2019 Td Win32asm 170.Asm

    39/40

    My_HexDDtoStringDec: ;don t forget to save register (pushad/popad);------------------------------------------------------------------------------; Converts a 32 bit value in EAX into an ascii decimal string to offset EDI.; Fast DWORD to decimal string conversion. Made by tE! // TMG.;------------------------------------------------------------------------------push 0h ;get some additional space on stack (10 bytes min.)

    push 0h ;'' upper dword is 0push eax ;'' lower dword -> 32 bit integer to convertfild qword ptr[esp] ;load 64 bit integer value on TOSfbstp real10 ptr[esp] ; store value as 80bit BCD valuepop ecxpop eaxmov edx,ecxmov ebx,eaxshr ecx,4shr eax,4

    and ebx,0000000Fh ;mask nibblesand edx,0F0F0F0Fh ;...and ecx,0F0F0F0Fhadd edx,30303030h ;build ascii numbersadd ecx,30303030h ;...add eax,30hadd ebx,30hmov [edi],al ;store in buffermov [edi+1],bl ;...mov [edi+8],clmov [edi+9],dl

    mov [edi+6],chmov [edi+7],dhbswap ecx ;endian conversion (486 processor needed)bswap edx ;dto.mov [edi+2],clmov [edi+3],dlmov [edi+4],chmov [edi+5],dhpop eax ;correct stackret

    ;******************************************************************************;==============================================================================; end Main = end of our program code;------------------------------------------------------------------------------end Main ;end of our program code, entry point

    ;==============================================================================; To create the exe file use this commands with your Microsoft Assembler/Linker;------------------------------------------------------------------------------; ml.exe /c /coff td__170.asm ;asm command

    ; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td__170.obj rsrc.obj ;link command

    Page 39

    td_win32asm_170.asm;==============================================================================

  • 7/23/2019 Td Win32asm 170.Asm

    40/40

    Page 40


Recommended