etch666 etch666
关注数: 16 粉丝数: 35 发帖数: 1,520 关注贴吧数: 3
与纯汇编俄罗斯方块的比较 使用sphinx c--单文件 /* Simple Tetris - game written in 1997 by Marko Kleine Berkenbusch */ ?resize TRUE ?use80386 ?alignword TRUE ?jumptomain NEAR ?include "VIDEO.H--" ?include "RANDOM.H--" ?include "KEYCODES.H--" ?include "SYSTEM.H--" ?include "VGA.H--" ?include "PORTS.H--" ?define PIT_CHANNEL_0 0x40 ?define PIT_CHANNEL_2 0x42 ?define PIT_CONTROL 0x43 ?define PIT_FREQ 0x1234DD ?define TIMER_INT 0x08 ?define PF_Width 12 ?define PF_Height 22 ?define BS_Width 11 ?define BS_Height 9 ?define Initialspeed 250 byte Tiles[7*16] = { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 } ; byte Block[99] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4, 4, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 } ; byte pal = FROM "TETRIS.PAL" ; byte logo = FROM "TETRLOGO.DAT" ; byte PField[PF_Width*PF_Height], TempPF[PF_Width*PF_Height] ; byte ActTile[16+1], NewTile[16+1] ; int TPos_x, TPos_y ; byte up, down, left, right, space, enter, quit ; word oldkeyboardhandle[2], oldtimerhandle[2] = {} ; word Lines ; word VScreen ; long Time, speed, timercount, clockticks ; interrupt timerhandle() { $ PUSH DS $ PUSH AX $ PUSH BX DS = CS ; Time++ ; clockticks += timercount ; IF (long clockticks >= 0x10000) { clockticks -= 0x10000 ; $ PUSHF $ CS: $ CALL FAR oldtimerhandle } EOI() ; $ POP BX $ POP AX $ POP DS } interrupt keyboardhandle() { $ PUSH DS $ PUSH AX $ PUSH BX DS = CS ; $ IN AL, 0x60 BL = TRUE ; IF ( AL >= 128 ) {AL -= 128; BL = FALSE; } IF ( AL == s_left ) left = BL; ELSE IF ( AL == s_right ) right = BL; ELSE IF ( AL == s_up ) up = BL; ELSE IF ( AL == s_down ) down = BL; ELSE IF ( AL == s_space ) space = BL; ELSE IF ( AL == s_return ) enter = BL ; ELSE IF ( AL == s_esc ) quit = TRUE ; EATKEY(); EOI(); $ POP BX $ POP AX $ POP DS } void SetTimer (word HandlerSeg, HandlerOfs, Freq) dword counter ; { IF (word Freq > 0) counter = PIT_FREQ / Freq ; ELSE counter = 0 ; timercount = counter ; OUTPORTB(0x34, , , PIT_CONTROL) ; OUTPORTB(counter, , , PIT_CHANNEL_0) ; counter = counter >> 8 ; OUTPORTB(counter, , , PIT_CHANNEL_0) ; OUTPORTB(0x90, , , PIT_CONTROL) ; GETINTVECT(#oldtimerhandle, TIMER_INT) ; clockticks = 0 ; SETINTVECT(, TIMER_INT, HandlerSeg, HandlerOfs) ; } void InitPField (word pfaddr) { AX = PF_Width*PF_Height ; DI = AX ; BX = pfaddr ; loop (DI) DSBYTE[DI+BX-0x01] = 0 ; SI = PF_Width ; loop (SI) { AX = SI + pfaddr ; BX = AX ; DSBYTE[BX-0x01] = -1 ; DSBYTE[PF_Width*PF_Height-PF_Width+BX-0x01] = -1 ; } SI = PF_Height ; loop (SI) { AX = SI-1*PF_Width+pfaddr ; DI = AX ; DSBYTE[DI] = -1 ; DSBYTE[DI+PF_Width-0x01] = -1 ; } } void OutTextXY (word Str, xb, yb; byte c) byte h ; word x, y ; { DI = Str ; FS = 0xF000 ; SI = 0xFA6E ; do { y = 8 ; loop (y) { AL = DSBYTE[DI] ; AH = 0 ; AX = AX << 3 + y - 1 ; BX = AX ; h = FSBYTE[SI+BX] ; x = 8 ; $ PUSH DI loop (x) { AL = h & 1 ; IF (AL <> 0) putpixel19(xb+x-1, yb+y, byte c) ; h >>= 1 ; } $ POP DI } xb += 8 ; DI++ ; } while (DSBYTE[DI] <> 0) ; } void InitScreen () int i, x, y ; { SETVIDEOMODE(0x13) ; SETVGADAC(0, , 768, , , #pal) ; FILLSCREEN19(0x01) ; i = 120 ; loop (i) { putpixel19(100+i, 7, 0x02) ; putpixel19(100+i, 8, 0x02) ; putpixel19(100+i, 9, 0x02) ; putpixel19(100+i, 10, 0x02) ; putpixel19(100+i, 191, 0x02) ; putpixel19(100+i, 192, 0x02) ; putpixel19(100+i, 193, 0x02) ; putpixel19(100+i, 194, 0x02) ; } i = 188 ; loop (i) { putpixel19(101, i+6, 0x02) ; putpixel19(102, i+6, 0x02) ; putpixel19(103, i+6, 0x02) ; putpixel19(104, i+6, 0x02) ; putpixel19(105, i+6, 0x02) ; putpixel19(216, i+6, 0x02) ; putpixel19(217, i+6, 0x02) ; putpixel19(218, i+6, 0x02) ; putpixel19(219, i+6, 0x02) ; putpixel19(220, i+6, 0x02) ; } OutTextXY("Next:", 245, 8, 4) ; OutTextXY("Lines:", 241, 110, 5) ; SI = 0 ; y = 47 ; loop (y) { x = 88 ; loop (x) { putpixel19(94-x, 70-y, byte logo[SI]) ; SI++ ; } } OutTextXY("von", 38, 96, 6) ; OutTextXY("Marko Kleine", 3, 122, 3) ; OutTextXY("Berkenbusch", 7, 134, 3) ; }
经典哒DirectDraw struct union和常量.asm文件谁有 struct IDirectDraw { // 这个struct结构体纯c不支持,c++和sphinx c--支持 long stdcall(*QueryInterface)(); long stdcall(*AddRef)(); long stdcall(*Release)(dword pdd); long stdcall(*Compact)(); long stdcall(*CreateClipper)(); long stdcall(*CreatePalette)(); long stdcall(*CreateSurface)(); long stdcall(*DuplicateSurface)(); long stdcall(*EnumDisplayModes)(); long stdcall(*EnumSurfaces)(); long stdcall(*FlipToGDISurface)(); long stdcall(*GetCaps)(); long stdcall(*GetDisplayMode)(); long stdcall(*GetFourCCCodes)(); long stdcall(*GetGDISurface)(); long stdcall(*GetMonitorFrequency)(); long stdcall(*GetScanLine)(); long stdcall(*GetVerticalBlankStatus)(); long stdcall(*Initialize)(); long stdcall(*RestoreDisplayMode)(); long stdcall(*SetCooperativeLevel)(); long stdcall(*SetDisplayMode)(); long stdcall(*WaitForVerticalBlank)(); long stdcall(*GetAvailableVidMem)(); long stdcall(*GetSurfaceFromDC)(); long stdcall(*RestoreAllSurfaces)(); long stdcall(*TestCooperativeLevel)(); long stdcall(*GetDeviceIdentifier)(); long stdcall(*StartModeTest)(); long stdcall(*EvaluateMode)(); }; struct IDirectDrawClipper{ // 这个struct结构体纯c不支持,c++和sphinx c--支持 long stdcall(*QueryInterface)(); long stdcall(*AddRef)(); long stdcall(*Release)(); long stdcall(*GetClipList)(); long stdcall(*GetHWnd)(); long stdcall(*Initialize)(); long stdcall(*IsClipListChanged)(); long stdcall(*SetClipList)(); long stdcall(*SetHWnd)(); }; struct IDirectDrawSurface{ // 这个struct结构体纯c不支持,c++和sphinx c--支持 long stdcall(*QueryInterface)(); long stdcall(*AddRef)(); long stdcall(*Release)(); long stdcall(*AddAttachedSurface)(); long stdcall(*AddOverlayDirtyRect)(); long stdcall(*Blt)(); long stdcall(*BltBatch)(); long stdcall(*BltFast)(); long stdcall(*DeleteAttachedSurface)(); long stdcall(*EnumAttachedSurfaces)(); long stdcall(*EnumOverlayZOrders)(); long stdcall(*Flip)(); long stdcall(*GetAttachedSurface)(); long stdcall(*GetBltStatus)(); long stdcall(*GetCaps)(); long stdcall(*GetClipper)(); long stdcall(*GetColorKey)(); long stdcall(*GetDC)(); long stdcall(*GetFlipStatus)(); long stdcall(*GetOverlayPosition)(); long stdcall(*GetPalette)(); long stdcall(*GetPixelFormat)(); long stdcall(*GetSurfaceDesc)(); long stdcall(*Initialize)(); long stdcall(*IsLost)(); long stdcall(*Lock)(); long stdcall(*ReleaseDC)(); long stdcall(*Restore)(); long stdcall(*SetClipper)(); long stdcall(*SetColorKey)(); long stdcall(*SetOverlayPosition)(); long stdcall(*SetPalette)(); long stdcall(*Unlock)(); long stdcall(*UpdateOverlay)(); long stdcall(*UpdateOverlayDisplay)(); long stdcall(*UpdateOverlayZOrder)(); long stdcall(*GetDDInterface)(); long stdcall(*PageLock)(); long stdcall(*PageUnlock)(); long stdcall(*SetSurfaceDesc)(); long stdcall(*SetPrivateData)(); long stdcall(*GetPrivateData)(); long stdcall(*FreePrivateData)(); long stdcall(*GetUniquenessValue)(); long stdcall(*ChangeUniquenessValue)(); long stdcall(*SetPriority)(); long stdcall(*GetPriority)(); long stdcall(*SetLOD)(); long stdcall(*GetLOD)(); }; struct IDirectDrawPalette{ // 这个struct结构体纯c不支持,c++和sphinx c--支持 long stdcall(*QueryInterface)(); long stdcall(*AddRef)(); long stdcall(*Release)(); long stdcall(*GetCaps)(); long stdcall(*GetEntries)(); long stdcall(*Initialize)(); long stdcall(*SetEntries)(); }; struct DDBLTFX{ DWORD dwSize; DWORD dwDDFX; DWORD dwROP; DWORD dwDDROP; DWORD dwRotationAngle; DWORD dwZBufferOpCode; DWORD dwZBufferLow; DWORD dwZBufferHigh; DWORD dwZBufferBaseDest; DWORD dwZDestConstBitDepth; union{ DWORD dwZDestConst; dword lpDDSZBufferDest; }DUMMYUNIONNAMEN1; DWORD dwZSrcConstBitDepth; union{ DWORD dwZSrcConst; dword lpDDSZBufferSrc; }DUMMYUNIONNAMEN2; DWORD dwAlphaEdgeBlendBitDepth; DWORD dwAlphaEdgeBlend; DWORD dwReserved; DWORD dwAlphaDestConstBitDepth; union{ DWORD dwAlphaDestConst; dword lpDDSAlphaDest; }DUMMYUNIONNAMEN3; DWORD dwAlphaSrcConstBitDepth; union{ DWORD dwAlphaSrcConst; dword lpDDSAlphaSrc; }DUMMYUNIONNAMEN4; union{ DWORD dwFillColor; DWORD dwFillDepth; DWORD dwFillPixel; dword lpDDSPattern; }DUMMYUNIONNAMEN5; DDCOLORKEY ddckDestColorkey; DDCOLORKEY ddckSrcColorkey; }; struct DDPIXELFORMAT{ DWORD dwSize; DWORD dwFlags; DWORD dwFourCC; union{ DWORD dwRGBBitCount; DWORD dwYUVBitCount; DWORD dwZBufferBitDepth; DWORD dwAlphaBitDepth; DWORD dwLuminanceBitCount; DWORD dwBumpBitCount; }DUMMYUNIONNAMEN1; union{ DWORD dwRBitMask; DWORD dwYBitMask; DWORD dwStencilBitDepth; DWORD dwLuminanceBitMask; DWORD dwBumpDuBitMask; }DUMMYUNIONNAMEN2; union{ DWORD dwGBitMask; DWORD dwUBitMask; DWORD dwZBitMask; DWORD dwBumpDvBitMask; }DUMMYUNIONNAMEN3; union{ DWORD dwBBitMask; DWORD dwVBitMask; DWORD dwStencilBitMask; DWORD dwBumpLuminanceBitMask; }DUMMYUNIONNAMEN4; union{ DWORD dwRGBAlphaBitMask; DWORD dwYUVAlphaBitMask; DWORD dwLuminanceAlphaBitMask; DWORD dwRGBZBitMask; DWORD dwYUVZBitMask; }DUMMYUNIONNAMEN5; }; struct DDOVERLAYFX{ DWORD dwSize; DWORD dwAlphaEdgeBlendBitDepth; DWORD dwAlphaEdgeBlend; DWORD dwReserved; DWORD dwAlphaDestConstBitDepth; union{ DWORD dwAlphaDestConst; dword lpDDSAlphaDest; }DUMMYUNIONNAMEN1; DWORD dwAlphaSrcConstBitDepth; union{ DWORD dwAlphaSrcConst; dword lpDDSAlphaSrc; }DUMMYUNIONNAMEN2; DDCOLORKEY dckDestColorkey; DDCOLORKEY dckSrcColorkey; DWORD dwDDFX; DWORD dwFlags; }; struct DDSURFACEDESC{ DWORD dwSize; DWORD dwFlags; DWORD dwHeight; DWORD dwWidth; union{ LONG lPitch; DWORD dwLinearSize; }DUMMYUNIONNAMEN1; DWORD dwBackBufferCount; union{ DWORD dwMipMapCount; DWORD dwZBufferBitDepth; DWORD dwRefreshRate; }DUMMYUNIONNAMEN2; DWORD dwAlphaBitDepth; DWORD dwReserved; LPVOID lpSurface; DDCOLORKEY ddckCKDestOverlay; DDCOLORKEY ddckCKDestBlt; DDCOLORKEY ddckCKSrcOverlay; DDCOLORKEY ddckCKSrcBlt; DDPIXELFORMAT ddpfPixelFormat; DDSCAPS ddsCaps; }; struct DDSURFACEDESC2{ DWORD dwSize; DWORD dwFlags; DWORD dwHeight; DWORD dwWidth; union{ LONG lPitch; DWORD dwLinearSize; }DUMMYUNIONNAMEN1; DWORD dwBackBufferCount; union{ DWORD dwMipMapCount; DWORD dwRefreshRate; DWORD dwSrcVBHandle; }DUMMYUNIONNAMEN2; DWORD dwAlphaBitDepth; DWORD dwReserved; LPVOID lpSurface; union{ DDCOLORKEY ddckCKDestOverlay; DWORD dwEmptyFaceColor; }DUMMYUNIONNAMEN3; DDCOLORKEY ddckCKDestBlt; DDCOLORKEY ddckCKSrcOverlay; DDCOLORKEY ddckCKSrcBlt; union{ DDPIXELFORMAT ddpfPixelFormat; DWORD dwFVF; }DUMMYUNIONNAMEN4; DDSCAPS2 ddsCaps; DWORD dwTextureStage; };
高级x86汇编sphinx c-- Direct3D9 代码 #include <d3dtypes.h> #define D3D_SDK_VERSION 31 extern WINAPI "D3D9.DLL"{ Direct3DCreate9(UINT SDKVersion); } WNDCLASSEX wc; DWORD hInstance; MSG msg; DWORD hWnd; char sClassName="D3D9 Sample"; char sTitle="D3D9 Window"; //IUnknown methods struct IDirect3D9 { /*** IUnknown methods ***/ long stdcall (*QueryInterface)(); long stdcall (*AddRef)(); long stdcall (*Release)(); /*** IDirect3D9 methods ***/ long stdcall (*RegisterSoftwareDevice)(); long stdcall (*GetAdapterCount)(); long stdcall (*GetAdapterIdentifier)(); long stdcall (*GetAdapterModeCount)(); long stdcall (*EnumAdapterModes)(); long stdcall (*GetAdapterDisplayMode)(); long stdcall (*CheckDeviceType)(); long stdcall (*CheckDeviceFormat)(); long stdcall (*CheckDeviceMultiSampleType)(); long stdcall (*CheckDepthStencilMatch)(); long stdcall (*CheckDeviceFormatConversion)(); long stdcall (*GetDeviceCaps)(); long stdcall (*GetAdapterMonitor)(); long stdcall (*CreateDevice)(); }; //IUnknown methods struct IDirect3DDevice9 { /*** IUnknown methods ***/ long stdcall (*QueryInterface)(); long stdcall (*AddRef)(); long stdcall (*Release)(); /*** IDirect3DDevice9 methods ***/ long stdcall (*TestCooperativeLevel)(); long stdcall (*GetAvailableTextureMem)(); long stdcall (*EvictManagedResources)(); long stdcall (*GetDirect3D)(); long stdcall (*GetDeviceCaps)(); long stdcall (*GetDisplayMode)(); long stdcall (*GetCreationParameters)(); long stdcall (*SetCursorProperties)(); long stdcall (*SetCursorPosition)(); long stdcall (*ShowCursor)(); long stdcall (*CreateAdditionalSwapChain)(); long stdcall (*GetSwapChain)(); long stdcall (*GetNumberOfSwapChains)(); long stdcall (*Reset)(); long stdcall (*Present)(); long stdcall (*GetBackBuffer)(); long stdcall (*GetRasterStatus)(); long stdcall (*SetDialogBoxMode)(); long stdcall (*SetGammaRamp)(); long stdcall (*GetGammaRamp)(); long stdcall (*CreateTexture)(); long stdcall (*CreateVolumeTexture)(); long stdcall (*CreateCubeTexture)(); long stdcall (*CreateVertexBuffer)(); long stdcall (*CreateIndexBuffer)(); long stdcall (*CreateRenderTarget)(); long stdcall (*CreateDepthStencilSurface)(); long stdcall (*UpdateSurface)(); long stdcall (*UpdateTexture)(); long stdcall (*GetRenderTargetData)(); long stdcall (*GetFrontBufferData)(); long stdcall (*StretchRect)(); long stdcall (*ColorFill)(); long stdcall (*CreateOffscreenPlainSurface)(); long stdcall (*SetRenderTarget)(); long stdcall (*GetRenderTarget)(); long stdcall (*SetDepthStencilSurface)(); long stdcall (*GetDepthStencilSurface)(); long stdcall (*BeginScene)(); long stdcall (*EndScene)(); long stdcall (*Clear)(); long stdcall (*SetTransform)(); long stdcall (*GetTransform)(); long stdcall (*MultiplyTransform)(); long stdcall (*SetViewport)(); long stdcall (*GetViewport)(); long stdcall (*SetMaterial)(); long stdcall (*GetMaterial)(); long stdcall (*SetLight)(); long stdcall (*GetLight)(); long stdcall (*LightEnable)(); long stdcall (*GetLightEnable)(); long stdcall (*SetClipPlane)(); long stdcall (*GetClipPlane)(); long stdcall (*SetRenderState)(); long stdcall (*GetRenderState)(); long stdcall (*CreateStateBlock)(); long stdcall (*BeginStateBlock)(); long stdcall (*EndStateBlock)(); long stdcall (*SetClipStatus)(); long stdcall (*GetClipStatus)(); long stdcall (*GetTexture)(); long stdcall (*SetTexture)(); long stdcall (*GetTextureStageState)(); long stdcall (*SetTextureStageState)(); long stdcall (*GetSamplerState)(); long stdcall (*SetSamplerState)(); long stdcall (*ValidateDevice)(); long stdcall (*SetPaletteEntries)(); long stdcall (*GetPaletteEntries)(); long stdcall (*SetCurrentTexturePalette)(); long stdcall (*GetCurrentTexturePalette)(); long stdcall (*SetScissorRect)(); long stdcall (*GetScissorRect)(); long stdcall (*SetSoftwareVertexProcessing)(); long stdcall (*GetSoftwareVertexProcessing)(); long stdcall (*SetNPatchMode)(); long stdcall (*GetNPatchMode)(); long stdcall (*DrawPrimitive)(); long stdcall (*DrawIndexedPrimitive)(); long stdcall (*DrawPrimitiveUP)(); long stdcall (*DrawIndexedPrimitiveUP)(); long stdcall (*ProcessVertices)(); long stdcall (*CreateVertexDeclaration)(); long stdcall (*SetVertexDeclaration)(); long stdcall (*GetVertexDeclaration)(); long stdcall (*SetFVF)(); long stdcall (*GetFVF)(); long stdcall (*CreateVertexShader)(); long stdcall (*SetVertexShader)(); long stdcall (*GetVertexShader)(); long stdcall (*SetVertexShaderConstantF)(); long stdcall (*GetVertexShaderConstantF)(); long stdcall (*SetVertexShaderConstantI)(); long stdcall (*GetVertexShaderConstantI)(); long stdcall (*SetVertexShaderConstantB)(); long stdcall (*GetVertexShaderConstantB)(); long stdcall (*SetStreamSource)(); long stdcall (*GetStreamSource)(); long stdcall (*SetStreamSourceFreq)(); long stdcall (*GetStreamSourceFreq)(); long stdcall (*SetIndices)(); long stdcall (*GetIndices)(); long stdcall (*CreatePixelShader)(); long stdcall (*SetPixelShader)(); long stdcall (*GetPixelShader)(); long stdcall (*SetPixelShaderConstantF)(); long stdcall (*GetPixelShaderConstantF)(); long stdcall (*SetPixelShaderConstantI)(); long stdcall (*GetPixelShaderConstantI)(); long stdcall (*SetPixelShaderConstantB)(); long stdcall (*GetPixelShaderConstantB)(); long stdcall (*DrawRectPatch)(); long stdcall (*DrawTriPatch)(); long stdcall (*DeletePatch)(); long stdcall (*CreateQuery)(); }; struct IDirect3DVertexBuffer9 { /*** IUnknown methods ***/ /*** IUnknown methods ***/ long stdcall (*QueryInterface)(); long stdcall (*AddRef)(); long stdcall (*Release)(); /*** IDirect3DResource9 methods ***/ long stdcall (*GetDevice)(); long stdcall (*SetPrivateData)(); long stdcall (*GetPrivateData)(); long stdcall (*FreePrivateData)(); long stdcall (*SetPriority)(); long stdcall (*GetPriority)(); long stdcall (*PreLoad)(); long stdcall (*GetType)(); long stdcall (*Lock)(); long stdcall (*Unlock)(); long stdcall (*GetDesc)(); }; /* Resize Optional Parameters */ struct D3DPRESENT_PARAMETERS { UINT BackBufferWidth; UINT BackBufferHeight; // D3DFORMAT BackBufferFormat; DWORD BackBufferFormat; UINT BackBufferCount; // D3DMULTISAMPLE_TYPE MultiSampleType; DWORD MultiSampleType; DWORD MultiSampleQuality; // D3DSWAPEFFECT SwapEffect; DWORD SwapEffect; HWND hDeviceWindow; BOOL Windowed; BOOL EnableAutoDepthStencil; // D3DFORMAT AutoDepthStencilFormat; DWORD AutoDepthStencilFormat; DWORD Flags; /* FullScreen_RefreshRateInHz must be zero for Windowed mode */ UINT FullScreen_RefreshRateInHz; UINT PresentationInterval; }; struct CUSTOMVERTEX { floatx; floaty; floatz; floatrhw; DWORDcolor; }; struct VERTICES { CUSTOMVERTEX vertice0; CUSTOMVERTEX vertice1; CUSTOMVERTEX vertice2; }; VERTICES vertices={ 200.0f, 50.0f, 0.5f, 1.0f, 0ffff0000h, 350.0f, 350.0f, 0.5f, 1.0f, 0ff00ff00h, 50.0f, 350.0f, 0.5f, 1.0f, 0ff00ffffh }; #define D3DSWAPEFFECT_DISCARD 1 #define D3DFMT_UNKNOWN 0 #define D3DDEVTYPE_HAL 1 #define D3DCREATE_SOFTWARE_VERTEXPROCESSING 0x00000020L #define D3DADAPTER_DEFAULT 0 #define D3DPOOL_DEFAULT 0 #define D3D_OK 0h DWORD D3D; DWORD D3DDevice; DWORD D3DVB; D3DPRESENT_PARAMETERS d3dpp; DWORD pVertices; DWORD InitD3D() { Direct3DCreate9(D3D_SDK_VERSION); if (EAX==0) return; D3D=EAX; EAX=#d3dpp; RtlZeroMemory(EAX, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed=TRUE; d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat=D3DFMT_UNKNOWN; EAX=#d3dpp; $push ebx EBX = D3D; EBX = DSDWORD[EBX]; EBX.IDirect3D9.CreateDevice(D3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, EAX, #D3DDevice); $pop ebx IF (EAX!=D3D_OK){ $XOR EAX, EAX RETURN; } $push ebx EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.CreateVertexBuffer(D3DDevice, sizeof(vertices), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, #D3DVB, 0); $pop ebx IF (EAX!=D3D_OK){ $XOR EAX, EAX RETURN; } $push ebx EAX=#pVertices; EBX = D3DVB; EBX = DSDWORD[EBX]; EBX.IDirect3DVertexBuffer9.Lock(D3DVB, 0, sizeof(vertices), EAX, 0); $pop ebx IF (EAX!=D3D_OK){ $XOR EAX, EAX RETURN; } RtlMoveMemory(pVertices, #vertices, sizeof(vertices)); $push ebx EBX = D3DVB; EBX = DSDWORD[EBX]; EBX.IDirect3DVertexBuffer9.Unlock(D3DVB); $pop ebx EAX=1; } ReleaseD3D() { $push ebx IF(D3DVB != 0) { EBX = D3DVB; EBX = DSDWORD[EBX]; EBX.IDirectDrawSurface.Release(D3DVB); D3DVB = 0; } IF(D3DDevice != 0) { EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirectDrawSurface.Release(D3DDevice); D3DDevice = 0; } IF(D3D != 0) { EBX = D3D; EBX = DSDWORD[EBX]; EBX.IDirectDrawSurface.Release(D3D); D3D = 0; } $pop ebx } //D3DCOLOR_XRGB D3DCOLOR_BLUE={0xff, 0, 0, 255}; //DWORD D3DCOLOR_BLUE=0xFF0000FF; //#define RGBA_MAKE(r,g,b,a) a<<8|r<<8|g<<8|b DWORD D3DCOLOR_BLUE=RGBA_MAKE(0,0,255,255); Render(){ EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.Clear(D3DDevice, 0, 0, D3DCLEAR_TARGET, D3DCOLOR_BLUE, 1.0f, 0); //------------------------------------ EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.BeginScene(D3DDevice); EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.SetStreamSource(D3DDevice, 0, D3DVB, 0, sizeof(CUSTOMVERTEX)); EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.SetFVF(D3DDevice, D3DFVF_XYZRHW | D3DFVF_DIFFUSE ); EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.DrawPrimitive(D3DDevice, D3DPT_TRIANGLELIST, 0, 1 ); EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.EndScene(D3DDevice); //------------------------------------ EBX = D3DDevice; EBX = DSDWORD[EBX]; EBX.IDirect3DDevice9.Present(D3DDevice, 0, 0, 0, 0); } WndProc(DWORD hWnd, uMsg, wParam, lParam) { EAX=uMsg; IF (EAX==WM_DESTROY) { PostQuitMessage(0); $XOR EAX, EAX; RETURN; } RETURN (DefWindowProc(hWnd, uMsg, wParam, lParam)); } main() { GetModuleHandle(0); wc.cbSize=sizeof(WNDCLASSEX); wc.style=CS_CLASSDC; wc.lpfnWndProc=#WndProc; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hInstance=EAX; wc.hIcon=0; wc.hCursor=0; wc.hbrBackground=0; wc.lpszMenuName=0; wc.lpszClassName=#sClassName; wc.hIconSm=0; RegisterClassEx(#wc); CreateWindowEx( 0, #sClassName, #sTitle, WS_VISIBLE | WS_OVERLAPPEDWINDOW, 0, 0, 512, 512, 0, 0, hInstance, 0); hWnd=EAX; ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); InitD3D(); IF (EAX!=1) GOTO Exit; do { IF(PeekMessage(#msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(#msg); DispatchMessageA(#msg); } // this does all the graphics update Render(); } while(msg.message != WM_QUIT); Exit: // Deinit ReleaseD3D(); ExitProcess(0); }
1 下一页